local Sit = script.Parent
local Animation = Sit:WaitForChild("SIt1TempB")
local Temp = false
local Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local Animator = Humanoid:FindFirstChild("Animator")
Sit.MouseButton1Click:Connect(function()
if Temp == false then
Temp = true
local AnimationTrack = Animator:LoadAnimation(Animation)
AnimationTrack:Play()
elseif Temp == true then
Temp = false
local AnimationTrack = Animator:LoadAnimation(Animation)
AnimationTrack:Stop()
end
end)
I made a script that was meant to play an animation when the GUI was clicked, and then when they want to stop the animation from playing, they could simply click the GUI button again.
Although the animation DOES play, it won’t stop, no matter how many times I edit the script, nothing seems to work. There’s no script errors either; atleast from what I see.
You’re creating 2 animation tracks for when you’re playing and stopping the animation.
Create 1 animationtrack outside the mousebutton1click event and use that to play and stop the animation.
local Sit = script.Parent
local Animation = Sit:WaitForChild("SIt1TempB")
local Temp = false
local Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local Animator = Humanoid:FindFirstChild("Animator")
local AnimationTrack = Animator:LoadAnimation(Animation)
Sit.MouseButton1Click:Connect(function()
if Temp == false then
Temp = true
AnimationTrack:Play()
elseif Temp == true then
Temp = false
AnimationTrack:Stop()
end
end)
You may also want to add checks to make sure the humanoid and animator actually exists, as you’re using FindFirstChild(), it can help prevent unexpected errors, and no problem.