I’m trying to make the player freeze and play an animation every time a button is pressed, and when pressed again, the animation should stop. That part works.
The part that doesn’t work is whenever the player is reset, either through commands or normally,
- the player will have to press the button twice just for the animation to actually play and
- the player will still be able to move during the animation
Here’s the local script where I think the error might be:
local EmotesFrame = script.Parent
local innerFrame = EmotesFrame.InnerFrame
local Input = game:GetService("UserInputService")
local module = require(game.ReplicatedStorage.Variables)
local player = game.Players.LocalPlayer
local character = player.Character
local animated = false
innerFrame.Back.MouseButton1Click:Connect(function()
EmotesFrame.Visible = false
end)
innerFrame.Lay.MouseButton1Click:Connect(function()
if animated == false then
local human = character:WaitForChild("Humanoid")
local anim = innerFrame.Lay.Animation
human.WalkSpeed = 0
human.JumpPower = 0
game.ReplicatedStorage.Animation:FireServer(anim, animated)
animated = true
else
local human = character:WaitForChild("Humanoid")
local anim = innerFrame.Lay.Animation
human.WalkSpeed = 16
human.JumpPower = 50
game.ReplicatedStorage.Animation:FireServer(anim, animated)
animated = false
end
end)
innerFrame.Sit.MouseButton1Click:Connect(function()
if animated == false then
local human = character:WaitForChild("Humanoid")
local anim = innerFrame.Sit.Animation
human.WalkSpeed = 0
human.JumpPower = 0
game.ReplicatedStorage.Animation:FireServer(anim, animated)
animated = true
else
local human = character:WaitForChild("Humanoid")
local anim = innerFrame.Sit.Animation
human.WalkSpeed = 16
human.JumpPower = 50
game.ReplicatedStorage.Animation:FireServer(anim, animated)
animated = false
end
end)
And, I doubt this is the problem, but I’ll include the serverscript, too, just in case:
game.ReplicatedStorage.Animation.OnServerEvent:Connect(function(player, animation, animated)
local anim
print(tostring(player), tostring(animated), tostring(animation))
if animated == false then
local character = player.Character
local human = character:WaitForChild("Humanoid")
anim = human:LoadAnimation(animation)
anim:Play()
else
local character = player.Character
local human = character:WaitForChild("Humanoid")
for _,thisTrack in pairs (human.Animator:GetPlayingAnimationTracks()) do
thisTrack:Stop()
end
end
end)