Animation isn't playing for some reason?

I have this script that’s supposed to make it so an animation plays when your sanity reaches 0. It just doesn’t play the animation or make the humanoids walkspeed 0.

I’ve tried making it myself, asking roblox ai, trying to playtest in the actual game. But still nothing i asked the roblox ai and it still doesn’t work? I’m wondering why it doesnt work even if i define the animation anywhere still doesnt work. (btw im not that good at scripting :sob:)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

	if val.Value <= 0 and not animationPlayed then
		animationPlayed = true
		local players = game:GetService("Players")
		for _, player in players:GetPlayers() do
			local character = player.Character
			if character then
				local humanoid = character:FindFirstChildOfClass("Humanoid")
				if humanoid then
					humanoid.WalkSpeed = 0
					local animator = humanoid:FindFirstChildOfClass("Animator")
					if animator then
						local animation = Instance.new("Animation")
						animation.AnimationId = "rbxassetid://73440534130575"
						local animationTrack = animator:LoadAnimation(animation)
						animationTrack:Play()
						print("work pls")
					end
				end
			end
		end
	end
end)

By the way that is the roblox ai, my version didn’t work at all so i had to ask it for help. by the way it does print but the animation doesnt play?

2 Likes

Make sure the animation’s ID can be played in your experience. If it cannot be played, then it is likely that you don’t have permission to it for your experience.

You can try to reupload the animation by using an animation spoofer plugin if it is not yours.

If you made it, maybe try to use

animationTrack.Stopped:Wait()

2 Likes

says wait isnt a valid member of animation track unless you mean smth else?

2 Likes

Sorry, I meant animationTrack.Stopped:Wait().

Let me know if that works.

2 Likes

Is that Animation asset owned by you? If it else, Animation may not play.

3 Likes

Yep i made it so im not sure why it doesnt work

1 Like

Didn’t work i put it after animationTrack:Play() then put that and after that a print statement, it would show the print statement but the animation didnt happen?

1 Like

Try adding this script to ensure that it is actually playing.

if animationTrack.IsPlaying == true then print(“animation is playing”) else print (“animation is not playing”) end

Let me know what it printed out!

1 Like

wait it played the animation on the server but not for the client, so ill just make a remote event i guess. Thank you for the help btw.

1 Like

Oh, okay.

I think it’s because you added a new track instance in the server instead of just adding it in the explorer page. No problem! Let me know if you need help.

I tried doing it with the remote event, but it just didnt work the script is here

local rs = game:GetService("ReplicatedStorage")
local sanityEvent = rs.Events.Remotes:WaitForChild("SanityDying")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humroot = char:WaitForChild("HumanoidRootPart")
local anim = rs.Anims.SanityFalling

sanityEvent.OnClientEvent:Connect(function()
    local animator = hum:FindFirstChildOfClass("Animator")
    if not animator then
        animator = Instance.new("Animator")
        animator.Parent = hum
    end
    local animTrack = animator:LoadAnimation(anim)
    task.wait()
    animTrack:Play()
end)

I fired this when the value reaches 0 in the server script but still doesnt work…?

Were there any errors or warnings in the output?

Try adding a print statement before and after the loading animation line. Let me know what it printed.

If none of those printed, add a print statement just below the OnClientEvent:Connect(function() line, and see if it is actually being fired properly.

Could you please check using the print() method above or below animtrack:Play() to see if there is a problem with the signal?

val:GetPropertyChangedSignal(“Value”):Connect(function()
if val.Value <= 0 and not animationPlayed then
animationPlayed = true
event:FireClient()
end
end) how am i gonan fire the event it says i need the player in the () but when i try to get the player it just doesnt work

It seems you are trying to fire an event to the client if a value is at 0. If you want to do this to all players as said here

just use FireAllClients().

This is a one player game, so that would be the same thing. (mb i forgot to mention this :sob:) So thats why i just want it to be client. Even if i were to do this it still doesnt work. The roblox ai just did this for me

Where is this LocalScript parented to?
It is likely that the LocalScript is parented to something in which it cannot run on.

For your information,
LocalScripts can run if they are parented to:

  • PlayerGui(StarterGui)
  • PlayerScripts(StarterPlayerScripts)
  • Player’s character(StarterCharacterScripts)
  • LocalScripts
  • …and more

but it cannot run if they are parented to:

  • Workspace
  • ReplicatedStorage
  • ServerScriptService

Try to add a print() statement in the first line, if it doesn’t print, this means it is not running.

Its in startercharacterscripts, so i dont know why its working…? ill add print statements and let u know

Send your console, when you run the game. I’m interested in that. Are you getting any errors?

I dont know how to define the player when i fire the event, event:FireClient() i need the player in the parentheses thats the reason why it doesnt work. So how can i define it game.Players.Playeradded doesnt work.

val:GetPropertyChangedSignal("Value"):Connect(function()
	if val.Value <= 0 and not animationPlayed then
		animationPlayed = true
		event:FireClient()
	end
end)