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

How come this script isn't playing any animation, when I press a key?

Asked by 9 years ago

This is what the script is supposed to do:

  • Hurt someone, when their right leg touches them, and push them back.

  • Play an animation, so it looks like their kicking the player.

This is what it's doing:

  • Hurting me, and damaging me, when I press the key.

  • Not playing any animations...

This is the script:

wait(2)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

repeat wait() until player.Character and player.Character:findFirstChild("Humanoid")

mouse.KeyDown:connect(function(key)
if key:byte() == 113 then
s = player.Character.Humanoid:LoadAnimation(game.Players.Animation)
s:Play()
player.Character.Humanoid:TakeDamage(50)
end
end)

3 answers

Log in to vote
0
Answered by 9 years ago

I dunno why the animation ain't playing; im not too experienced with those myself. However, the reason you are damaging yourself is written write there: "player.Character.Humanoid:TakeDamage(50)" You literally made the own character take damage :P

Ad
Log in to vote
0
Answered by 9 years ago

He wants to take damage and have the animation

Log in to vote
0
Answered by
nilVector 812 Moderation Voter
9 years ago

I'm not sure if this'll work, because I don' have any animations to test this with. Let me know if this works. I think your mistake was not putting "local" behind your variable "s", which you defined as your animation loaded into your humanoid. If you don't put local, then it won't know to do it to your specific character. If that doesn't work, then I'm sorry. I really don't know much about playing animations and stuff like that.

wait(2)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

repeat wait() until player.Character and player.Character:findFirstChild("Humanoid")

mouse.KeyDown:connect(function(key)
    if key:byte() == 113 then
        local s = player.Character.Humanoid:LoadAnimation(game.Players.Animation)
        s:Play()
        player.Character.Humanoid:TakeDamage(50)
    end
end)

Answer this question