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 )
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?
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.
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?
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…?
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
This is a one player game, so that would be the same thing. (mb i forgot to mention this ) 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
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)