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

Where did I go wrong in this animation player localscript?

I have made a Text Button that should make an animation play in the person who clicks it, but it doesn't work. Where did I go wrong? It doesn't work in ROBLOX studio or the game. I was wondering how to fix the script. It is a Local Script inside the Text Button.

local animation = Instance.new("Animation")
animation.animationId ="rbxassetid://2778577214"


local trackanimation = nil
local playability = true
  
function playanimation(AnimationSource)
 if playability == true then
  local plr = game.players.localplayer
  trackanimation = plr.character.humanoid:loadanimation(animation)
  
  trackanimation.keyframereached:connect(function()
   print("ChasingNachos")
  end) 
     trackanimation:play()
 end
 
end
script.Parent.MouseButton1Click:connect(playanimation)?

4 comments

0

Don't forget to accept my answer if it solves your problem.

0

please forget

0

shup gisoni01

0

You use AnimationId. Not animationId

1 answer

✓ Accepted answer

Well first off everything is lowercase, and you have a random ? at the end of the script. Lua is case sensitive, so you obviously need your lowercases and uppercases. Roblox uses PascalCase, which is really just all the first letters of each word in uppercase. For example FindFirstChild. It is all "one word" and you can notice each word has its first letter in uppercase.

local animation = Instance.new("Animation")
animation.animationId ="rbxassetid://2778577214"
local trackanimation = nil
local playability = true
local player = game:GetService("Players").LocalPlayer
-- # recommended way of getting services. Notice the PascalCase 'GetService'

local function playanimation() -- # localise variable 
    trackanimation = player.Character.Humanoid:LoadAnimation(animation)

    trackanimation.KeyFrameReached:Connect(function(keyframe)
        print("ChasingNachos")
    end)
    
    if playability then -- # no need for == true
         trackanimation:Play()
    end
end
script.Parent.MouseButton1Click:Connect(playanimation)

Your variables can use any casing you want.

4 comments

2

-rep is stupid dumb dumb

0

heck

0

It doesn't work. It says that animationid is not a valid member of animation.

1

Use AnimationId

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