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

How do I make an Animation Deal Damage?

Asked by 8 years ago

How do I make an animation cause damage? Like, I made a Roundhouse kick animation. And I want it to cause damage to the person it touches. I tired, it won't work.

wait(2) 

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local humanoid = player.Character.Humanoid 
local s = humanoid:LoadAnimation(game.StarterPack.RoundHouse.Animation)

Mouse.KeyDown:connect(function(key)
if key:lower() == "f" and humanoid then
    s:Play() 
game.Players.Character.Humanoid.Health = -20
wait(5)
end
end)

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

Let's start out by tabbing your code correctly:

wait(2) --Wait 2 seconds

local player = game.Players.LocalPlayer --Get the LocalPlayer
local Mouse = player:GetMouse() --Get the Mouse
local humanoid = player.Character.Humanoid --Get the Humanoid
local s = humanoid:LoadAnimation(game.StarterPack.RoundHouse.Animation) --Load animation into Humanoid to be used as a variable

Mouse.KeyDown:connect(function(key) --When they press a key
    if key:lower() == "f" and humanoid then --If that key is f and the humanoid is not nil
        s:Play() -- Play the roundhouse kick animation
        game.Players.Character.Humanoid.Health = -20 --Set the LocalPlayer's health to -20
        wait(5) --Wait 5 seconds
    end
end)

Let's now read all of my annotations, explaining what your script does in list form: Wait 2 seconds Get the LocalPlayer Get the Mouse Get the Humanoid Load animation into Humanoid to be used as a variable

When they press a key If that key is f and the humanoid is not nil Play the roundhouse kick animation Set the LocalPlayer's health to -20 Wait 5 seconds Done

I think you can see the problem from this now. In order to make the Kick do damage, you need to do a connection function for if LocalPlayer hits the other. If he does hit the player, do damage.

-- This code sets the health to -20
game.Players.Character.Humanoid.Health = -20 

--This code subtracts 20 from the health
game.Players.Character.Humanoid.Health = game.Players.Character.Humanoid.Health - 20

-- This code also subtracts 20 from the health, but this way is preferred.
game.Players.Character.Humanoid:TakeDamage(20)
0
Thanks but how do I do a connection function? I'm new at scripting. I only know basics. james24dj 90 — 8y
Ad

Answer this question