Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

when i touch a humanoid it kills me! help??

Asked by 6 years ago

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

01player = game.Players.localPlayer
02local Char
03    repeat
04        Char = player.Character
05        wait()
06until Char
07 
08local Humanoid = Char:WaitForChild("Humanoid")
09local Player = game.Players.LocalPlayer
10local Mouse = Player:GetMouse()
11local dmg = true
12 
13Mouse.KeyDown:connect(function(key)
14 if key == "q" then
15  local an = script.Parent.Humanoid:LoadAnimation(script.Animation)
View all 33 lines...
0
you can touch humanoids?! O_O!!!! Fifkee 2017 — 6y
0
ok, next time try using User Input service instead of mouse.KeyDown theking48989987 2147 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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 :)

0
Actually ignore the 2nd instruction. Create another if statement under your "Touched" function to check debounce == false. NoirPhoenix 148 — 6y
0
use edit button at botom of ur answor Fifkee 2017 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

The damage isn't encased in the "hit" function you referred to. Add something like..

1function 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
8end

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)

Answer this question