so i am trying too make a punch script that does damage according to eaderstats, and instead of increasing it just kills me when i touch the root part of a humanoid NOTE: this is a localscript
player = game.Players.localPlayer local Char repeat Char = player.Character wait() until Char local Humanoid = Char:WaitForChild("Humanoid") local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local dmg = true Mouse.KeyDown:connect(function(key) if key == "q" then local an = script.Parent.Humanoid:LoadAnimation(script.Animation) an:Play() script.Parent.LeftHand.Touched:connect(function(hit) local Player = game.Players.LocalPlayer local LB = Player:WaitForChild("leaderstats") local p = LB:WaitForChild("Power") local damage = 0.1 * p.Value wait(1) Humanoid:TakeDamage(damage) dmg = false wait(1) dmg = true end) end end)
Hi, the reason u keep dying instantly is because there is no debounce to fall on therefore your script is getting triggered multiple times.
To do this:
1) add a variable (local debounce = false) 2) add validation to your keybind detection (if key == "q" and debounce == false) then 3)after that validation turn the debounce to true 4) after the humanoid has taken damage then make debounce = to false again
Hope this helps :)
The damage isn't encased in the "hit" function you referred to. Add something like..
function hit() local eHumanoid = script.Parent.LeftHand.Touched.Parent:FindFirstChild('Humanoid') -- ^ Finds out if the thing you're punching is a Humanoid. local damage = 0.1 * p.Value -- The Damage value. if (eHumanoid) then -- Checks if the Variable found a humanoid. eHumanoid:TakeDamage(damage) -- If it did, said humanoid takes damage. end end
This may need some tweaking, but judging from your code its the best I could come up with.
EXTRA NOTES: Don't use connect, it's been updated to Connect (with a capital C)