#Health damage bug
1 messages · Page 1 of 1 (latest)
local Tool = script.Parent
local Debris = game:GetService("Debris")
local Players = game:GetService("Players")
-- Damage values for different body parts
local DAMAGE_VALUES = {
["Left Arm"] = 25,
["Right Arm"] = 25,
["Left Leg"] = 50,
["Right Leg"] = 50,
["Head"] = 100,
["UpperTorso"] = 100,
["LowerTorso"] = 100,
["LeftHand"] = 10,
["RightHand"] = 10
}
-- Cooldown to prevent rapid damage
local COOLDOWN_TIME = 0.5
local hitCooldowns = {}
local function getDamageForPart(partName)
-- Check for exact match first
if DAMAGE_VALUES[partName] then
return DAMAGE_VALUES[partName]
end
-- Check for partial matches
for key, damage in pairs(DAMAGE_VALUES) do
if string.find(string.lower(partName), string.lower(key))
or string.find(string.lower(key), string.lower(partName)) then
return damage
end
end
-- Default damage for any other part
return 25
end
local function onTouched(hit)
-- 🔒 ONE-LINE LUNGE CHECK (entire condition)
if not (Tool:FindFirstChild("IsLunging") and Tool.IsLunging.Value) then return end
local character = hit.Parent
if not character then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health <= 0 then return end
-- Prevent hitting the owner
local toolOwner = Players:GetPlayerFromCharacter(Tool.Parent)
local hitPlayer = Players:GetPlayerFromCharacter(character)
if hitPlayer and hitPlayer == toolOwner then return end
-- Cooldown check
if hitCooldowns[character] then return end
hitCooldowns[character] = true
task.delay(COOLDOWN_TIME, function()
hitCooldowns[character] = nil
end)
-- Apply damage - works for any part of a humanoid
local damage = getDamageForPart(hit.Name)
humanoid:TakeDamage(damage)
print("Dealt " .. damage .. " damage to " .. character.Name .. " via " .. hit.Name)
-- Visual hit effect
local effect = Instance.new("ParticleEmitter")
effect.Parent = hit
effect.Color = ColorSequence.new(Color3.new(0, 1, 1))
effect.Size = NumberSequence.new(0.5)
effect.Transparency = NumberSequence.new({
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(1, 1)
})
effect.Acceleration = Vector3.new(0, 5, 0)
effect.Lifetime = NumberRange.new(0.5, 1)
effect.Rate = 50
effect.Enabled = true
Debris:AddItem(effect, 1)
end
-- Connect touch events to all tool parts
for _, part in ipairs(Tool:GetDescendants()) do
if part:IsA("BasePart") then
part.Touched:Connect(onTouched)
end
end
Damage script ^
ToolLungeScript v
-- Michael's Tron Disc - Client Lunge Animation (LocalScript)
local Tool = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- 🔁 Lunge animation combo order
local LUNGE_ANIMATIONS = {
"rbxassetid://90845992190498", -- 1st hit
"rbxassetid://108524928213156", -- 2nd hit
"rbxassetid://106536001216832", -- 3rd hit
}
local LUNGE_FORCE = 0
local LUNGE_DURATION = 0.25
local NORMAL_COOLDOWN = 0.8
local COMBO_COOLDOWN = 1.5 -- longer cooldown after 3rd hit
local canLunge = true
local comboIndex = 1
local function getHumanoidAndRoot(character)
if not character then return end
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if not humanoid then return end
local root =
character:FindFirstChild("HumanoidRootPart")
or character:FindFirstChild("Torso")
or character:FindFirstChild("UpperTorso")
return humanoid, root
end
Tool.Activated:Connect(function()
if not canLunge then return end
canLunge = false
local character = player.Character
if not character then
canLunge = true
return
end
local humanoid, root = getHumanoidAndRoot(character)
if not humanoid or not root then
canLunge = true
return
end
-- Animator
local animator = humanoid:FindFirstChildWhichIsA("Animator")
if not animator then
animator = Instance.new("Animator")
animator.Parent = humanoid
end
-- ▶ Play combo animation in order
local animation = Instance.new("Animation")
animation.AnimationId = LUNGE_ANIMATIONS[comboIndex]
local track = animator:LoadAnimation(animation)
track.Priority = Enum.AnimationPriority.Action
track:Play()
-- 🔔 Inform server: lunge active
if Tool:FindFirstChild("IsLunging") then
Tool.IsLunging.Value = true
end
-- Client-predicted movement
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(1e5, 0, 1e5)
bodyVelocity.Velocity = root.CFrame.LookVector * LUNGE_FORCE
bodyVelocity.Parent = root
task.delay(LUNGE_DURATION, function()
bodyVelocity:Destroy()
if Tool:FindFirstChild("IsLunging") then
Tool.IsLunging.Value = false
end
end)
-- ⏱ Cooldown handling
local cooldownTime = NORMAL_COOLDOWN
if comboIndex >= #LUNGE_ANIMATIONS then
-- End of combo
comboIndex = 1
cooldownTime = COMBO_COOLDOWN
else
comboIndex += 1
end
task.delay(cooldownTime, function()
canLunge = true
end)
end)
What is this script for?
Is it local or not
oh my god it is
any he is dealing damage on the client
wowww
@lofty falcon what ai did you use for this
I mean I've seen people try doing that
If you are trying to make a sword I can recommend a great tutorial
This code looks pretty ahh tbh. I recommend coding with AI help not entirely with ai can't really help
Any errors in output?
Both, chatgpt and AI assistant
The lunge doesn't give damage to the touched parts of the body
Lunge hit of the tool
Use Claude instead if you’re just gonna vibe code stuff. But I highly highly recommend against it
Do you even know what the output is?
Cuz this is definitely not what it says
I'm 15
It won't allow me
I asked AI to make connection to the humanoid damage so the tool damages the object that has a humanoid, only when you pressed left click
I added three lunge variants
** You are now Level 2! **
can't help then sry
Man just learn scripting yourself instead of vibe coding
** You are now Level 6! **
It’s not hard really