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

How to make a chatted animation work with gamepass?

I'm new to scripting & trying to make a gamepass which plays animations on specific chatted messages, but I don't know where I've gone wrong. Nothing showing in output or dev console. Anyone able to help?

service = game:GetService("GamePassService")
gamepass = 000000 --edit this later
player = game.Players
humanoid = player:WaitForChild("Humanoid")
animation = game.Lighting("Animation") 
play = humanoid:LoadAnimation(animation) 

wait()

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.Chatted:connect(function(Message)
		   if Message == "/e test" and
			  service:PlayerHasPass(player, gamepass) then
			  play:Play()
		end
	end)
end)



`

1 comment

0

From what I've read, it should be playing, unless the Animation isn't loading correctly. Make sure that the animation is either free, or in your inventory.

1 answer

✓ Accepted answer

The problem here is: You're not referencing the player. In line three, the variable is referencing game.Players, which is a service. After fixing that, you'd have to use Player.Character in line 4 to reference the humanoid. The final problem is you didn't use WaitForChild on the animation variable. Here's a fixed version of your code:

service = game:GetService("GamePassService")
gamepass = 000000 --edit this later
player = game:GetService("Players").LocalPlayer
humanoid = player.Character:WaitForChild("Humanoid")
animation = game.Lighting:WaitForChild("Animation") 
play = humanoid:LoadAnimation(animation) 

wait() --This could possibly prevent the first player that entered from running the below code.

game:GetService("Players").PlayerAdded:Connect(function(Player)
    Player.Chatted:connect(function(Message)
           if Message == "/e test" and
              service:PlayerHasPass(player, gamepass) then
              play:Play()
        end
    end)
end)




2 comments

0

Thank you, but now it's showing this error message in the output - "Script:4: attempt to index global 'player' (a nil value)" How would I fix it?

0

That means that you're running this in a server script. LocalPlayer can only be used in a LocalScript. Put this all in a LocalScript, and you should be good(Assuming that you're not using Filtering Enabled[Which I reccommend using]).

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