Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make this script deal damage?

This script is for a kicking animation, and I want it to deal damage whenever the players right leg (the one in the animation) hits another player.



local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")


local Mouse = Player:GetMouse()

local kicking = Instance.new("Animation", Humanoid)

kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670"

local function keyDown(key)
    key = key:lower()
    if key == 't' then
        local animTrack = Humanoid:LoadAnimation(kicking)
        animTrack:Play() 
		end
    end 

Mouse.KeyDown:connect(keyDown)

2 answers

✓ Accepted answer

sure. [UPDATED]

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")


local Mouse = Player:GetMouse()

local kicking = Instance.new("Animation", Humanoid)

kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670"

local function keyDown(key)
    key = key:lower()
    if key == 't' then
        local animTrack = Humanoid:LoadAnimation(kicking)
        animTrack:Play() 
    end
 end 

function checkHit()
    local rLeg = Character:WaitForChild("Right Leg")
    local damage = 15

    rLeg.Touched:connect(function(toucher)
      if toucher.Parent. Humanoid then
          local hitHuman = toucher.Parent.Humanoid
		 hitHuman.Health = hitHuman.Health - damage
	 elseif toucher.Humanoid then
		 local hitHuman2 = toucher.Humanoid
		 hitHuman2.Health = hitHuman2.Health - damage
	 end 
end)
    end)
end

Mouse.KeyDown:connect(keyDown, checkHit)

6 comments

0

What would I do to check if it was a humanoid?

0

you could try: if toucher.Parent.Humanoid or toucher.Humanoid then humanoid.Health = humanoid.Health - damage

0

It keeps saying that It expects a" )" to close at line 24, but that still doesn't work

0

rLeg.Touched:connect(function(toucher) if toucher.Parent. Humanoid then local hitHuman = toucher.Parent.Humanoid hitHuman.Health = hitHuman.Health - damage elseif toucher.Humanoid then local hitHuman2 = toucher.Humanoid hitHuman2.Health = hitHuman2.Health - damage end end)

0

I tested it on a model and nothing happend ( I removed the end on line 33)

0

The model had a Humanoid in it

Glitch you're right but the Player.Character or Player.CharacterAdded:wait() the "player" is a nil value so it would have to be changed or it would bug and you would have to fix the script but gg GlitchMaster.

3 comments

0

WHat do I do to change it?

0

I might ask a friend that is a Scripter about it and I will get back to you soon.

0

Yea, Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.