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
01 | player = game.Players.localPlayer |
02 | local Char |
03 | repeat |
04 | Char = player.Character |
05 | wait() |
06 | until Char |
07 |
08 | local Humanoid = Char:WaitForChild( "Humanoid" ) |
09 | local Player = game.Players.LocalPlayer |
10 | local Mouse = Player:GetMouse() |
11 | local dmg = true |
12 |
13 | Mouse.KeyDown:connect( function (key) |
14 | if key = = "q" then |
15 | local an = script.Parent.Humanoid:LoadAnimation(script.Animation) |
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..
1 | function hit() |
2 | local eHumanoid = script.Parent.LeftHand.Touched.Parent:FindFirstChild( 'Humanoid' ) |
3 | -- ^ Finds out if the thing you're punching is a Humanoid. |
4 | local damage = 0.1 * p.Value -- The Damage value. |
5 | if (eHumanoid) then -- Checks if the Variable found a humanoid. |
6 | eHumanoid:TakeDamage(damage) -- If it did, said humanoid takes damage. |
7 | end |
8 | 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)