This is my first time making a game, so keep in mind I have no clue how to script and how to fix this. I am making a dance game in Roblox where when you click on a tool the character does the animation. I used a script I found that is:
script.Parent.Selected:connect(function(m) m.Button1Down:connect(function() hum = game.Players.LocalPlayer.Character.Humanoid anim_feet = hum:LoadAnimation(script.Parent.Animation) current = anim_feet current:Play() end) end)
This script works fine in Roblox Studio, but when I go into my game in Roblox, it doesn't work. Is there a way to fix this script to make it work in Roblox? I'd be very thankful if someone could help me out.
I've seen this problem before and had my beef with it, and it is because of game.Players.LocalPlayer being not able to be specified in a server sided script. It only works in Roblox studio because there is only one player, you, playing in the game at that time, so local player means the only player in the game in Roblox studio. I'd suggest looking into the Roblox studio "wiki" here about the client and server-side stuff, and more, cause im no good at explaining stuff most of the time which the website is GREAT at.
Here is a re-made script that should work,
script.Parent.Selected:connect(function(mouse) mouse.Button1Down:connect(function() local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent) local hum = player.Character.Humanoid local anim_feet = hum:LoadAnimation(script.Parent.Animation) local current = anim_feet current:Play() end) end)
Tell me if anything goes wrong!
Sincerely,
Narwhal