Animation not working

I want to make a GUI button for this animation the problem is it will only work in Studio, not the game.

image

studio :


game:

here is the game link: Escape Button - Roblox

local player = game:GetService("Players").LocalPlayer
Character = player.Character or player.CharacterAdded:Wait()
Humanoid = Character:WaitForChild("Humanoid")
Animator = Humanoid:WaitForChild("Animator")

local animationCrouch = Instance.new("Animation",script)
animationCrouch.AnimationId = "rbxassetid://6269140286"
local loadedAnim = Animator:LoadAnimation(animationCrouch)

local animationStatus = false

script.Parent.MouseButton1Click:Connect(function()
    if animationStatus == false then		
		loadedAnim:Play()
		Humanoid.WalkSpeed = 10
		animationStatus = true
	else
		loadedAnim:Stop()
		Humanoid.WalkSpeed = 16
		animationStatus = false
	end
end) 
6 Likes

The animation is playing, but it’s not playing the right animation. Can you check the animation ID and make sure that it’s not wrong?

1 Like

It is the right animation here is the ID from the animation
RobloxStudioBeta_FMfFH5lvl0

1 Like

maybe try calling Animator:LoadAnimation() instead of Humanoid:LoadAnimation() like this
local anim = script.Animation
local player = game.Players.LocalPlayer
local animationID = “rbxassetid://6269140286”
animationStatus = false

script.Parent.MouseButton1Click:Connect(function()
if animationStatus == false then
animationStatus = true
local animationCrouch = Instance.new(“Animation”)
animationCrouch.AnimationId = animationID
local loadedAnim = player.Character.Humanoid:WaitForChild(“Animator”):LoadAnimation(animationCrouch)
loadedAnim:Play()
player.Character.Humanoid.WalkSpeed = 10
else
for i , v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
player.Character.Humanoid.WalkSpeed = 16
animationStatus = false
end
end)

5 Likes

it is still not working, also I updated the script

Knew it! The function was depricated.

2 Likes

Hope this works:

local player = game:GetService("Players").LocalPlayer
Character = player.Character or player.CharacterAdded:Wait()
Humanoid = Character:WaitForChild("Humanoid")
Animator = Humanoid:WaitForChild("Animator")

local animationCrouch = Instance.new("Animation",script)
animationCrouch.AnimationId = "rbxassetid://6269140286"
local loadedAnim = Animator:LoadAnimation(animationCrouch)

local animationStatus = false

script.Parent.MouseButton1Click:Connect(function()
    if animationStatus == false then		
		loadedAnim:Play()
		Humanoid.WalkSpeed = 10
		animationStatus = true
	else
		loadedAnim:Stop()
		Humanoid.WalkSpeed = 16
		animationStatus = false
	end
end)

also, this is not working, I have updated the script

Are they any errors when you click the button?

No, I don’t see any errors when I click the button

Try stopping and destroying all animations loaded into the character model. Then, load the animation you’d like to play and play it. If it works, then something is overriding your animation.

If not, then double check the animation ID and make sure it’s correct. Also, you can try loading it before hand with the ContentProvider. It’s possible that it’s not loading right away for whatever reason.

(Sometimes uploading assets take a bit of time before being useable in-game. They must be verified and approved before the public can see it in-game. In case there are any TOS violations)

I have a past post that has a code snippet on how to stop all animations in a character, found here.

when you say this

do you mean deleting the animate script in my player

You could delete it. But the main goal is to remove all loaded animations and only play the animation you’re trying to play.

it is not the first one or the second so it might not be verified

Is the game a group game and is the animation a group animation or not?

I will check and yes it is a group game

and I believe it is a group animation

1 Like

Just check if it a group animation if it is your own animation then try to make a group animation.

9 Likes

Thank you I did not think it was that simple

1 Like

im frustated i had to do ALL the animations i worked hard on for 7 months i just finished it… again

4 Likes