I'm making a dance simulator. And I need dances right? So I wanted to make a gui that plays a dance when you click it, when you click it again, it stops. I tried doing this:
function click() local Animation = Instance.new("Animation") local animTrack = game.Player.LocalPlayer.Character.Humanoid:LoadAnimation(Animation) Animation.AnimationId = "http://www.roblox.com/asset?id=234539352" animTrack:Play() if script.Parent.MouseButton1Click and animTrack.Playing == true then animTrack:Stop() end end script.Parent.MouseButton1Click:connect(click)
None of the script works.
I got this from the output:
Player is not a member of DataModel
Can anyone help me?
Small Typo with 'Player'
'Player' should be 'Players', also no need for the conditional check on MouseButton1Click, and also the reason this is occurring is because you're stopping it each time you play it.
Try using some debounces!
Also, we don't want to keep loading in new Instances to the player each time they click the button! Let's try something as so:
Hint, sometimes using functions to organize things can help a lot. Here's a way I would organize it to make it neater for future scripts as-well.
local plr = game.Players.LocalPlayer local chr = plr.Character or plr.CharacterAdded:wait() local Animation; local animTrack; local playing = false; function newAnimation(Id) Animation = Instance.new("Animation") animTrack = chr["Humanoid"]:LoadAnimation(Animation) Animation.AnimationId = "http://www.roblox.com/asset?id=" .. Id end function hasAnimation(Id) if chr:FindFirstChild("Animation") and chr["Animation"].AnimationId == "http://www.roblox.com/asset?id="..Id then return true end return false end function stop() animTrack:Stop() playing = false; end function play() animTrack:Play() playing = true; end script.Parent.MouseButton1Down:connect(function() print("Clicked!") if not hasAnimation(234539352) then newAnimation(234539352) end if not playing then play() elseif playing then stop() end end)
Simple answer: You forgot the 's' in "Players" on line 3.
I'm not sure if this'll fix the entire thing, but from what I see, it should. Hope I helped :P