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 9 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.

01wait(2)
02 
03local player = game.Players.LocalPlayer
04local Mouse = player:GetMouse()
05local humanoid = player.Character.Humanoid
06local s = humanoid:LoadAnimation(game.StarterPack.RoundHouse.Animation)
07 
08Mouse.KeyDown:connect(function(key)
09if key:lower() == "f" and humanoid then
10    s:Play()
11game.Players.Character.Humanoid.Health = -20
12wait(5)
13end
14end)

1 answer

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

Let's start out by tabbing your code correctly:

01wait(2) --Wait 2 seconds
02 
03local player = game.Players.LocalPlayer --Get the LocalPlayer
04local Mouse = player:GetMouse() --Get the Mouse
05local humanoid = player.Character.Humanoid --Get the Humanoid
06local s = humanoid:LoadAnimation(game.StarterPack.RoundHouse.Animation) --Load animation into Humanoid to be used as a variable
07 
08Mouse.KeyDown:connect(function(key) --When they press a key
09    if key:lower() == "f" and humanoid then --If that key is f and the humanoid is not nil
10        s:Play() -- Play the roundhouse kick animation
11        game.Players.Character.Humanoid.Health = -20 --Set the LocalPlayer's health to -20
12        wait(5) --Wait 5 seconds
13    end
14end)

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.

1-- This code sets the health to -20
2game.Players.Character.Humanoid.Health = -20
3 
4--This code subtracts 20 from the health
5game.Players.Character.Humanoid.Health = game.Players.Character.Humanoid.Health - 20
6 
7-- This code also subtracts 20 from the health, but this way is preferred.
8game.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 — 9y
Ad

Answer this question