Need help in playing an animation after firing at event

Could i get suggestions on what to use in my code so i could make the animation fire after the event fires?

1 Like

Welcome to the DevForum!

One way would be to have the server fire the client event and on the client when it gets the event call you could use Humanoid:LoadAnimation and load the animation into the humanoid then play it from there.

What you’re trying to achieve isn’t really clear and it’s ambiguous. Do you mean you want to play an animation when a RemoteEvent is fired, or do you mean you want to play an animation when an event, like part.Touched for example, is fired?

I made a script in a part that fires an event in replicatedstorage, in my startercharactorscripts i got a localscript that actives when the event fires

does it have to be a local script or just a script

You need to use OnClientEvent on the client to receive the signal from the server to fire the event. To play the animation, you need to use LoadAnimation, a function of the Humanoid, to return a controller that allows you to play the animation:

local event = game.ReplicatedStorage.YourEvent
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local aninTrack = humanoid:LoadAnimation(YourAnimation)

event.OnClientEvent:Connect(function()
    animTrack:Play()
end)
Event:Wait()
AnimationTrack:Play()

Whatever your event is, call Wait to wait for it to fire. Your thread will yield until the event is fired, which then the animation plays afterward.

I have tried that already, i looked in roblox dev hub and it did not work.

Hold on im gonna try it real quick.

Can i fire two clients with the same event or do i have to make seperate events?

because if i do need to make seperate events then i think that’ll fix my problem,
but if not its probably something else.

You can - you don’t need to make separate events

1 Like

this is what i got

post the code you used
//30characters\

Part’s code:

script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild(“Humanoid”) then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
game.ReplicatedStorage.PoisionAreaHandler:FireClient(player)
end
end)

your code(in serverscriptservice):

local event = game.ReplicatedStorage.PoisionAreaHandler
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild(“Humanoid”)
local animTrack = humanoid:LoadAnimation(4473996043)

event.OnClientEvent:Connect(function()
animTrack:Play()
end)

This should be in a local script

localscript in serverscriptservice yeah?

No, local scripts won’t run in ServerScriptService. You should put the script in StarterPack or StarterCharacterScripts

I put it in starterpack and it errors me that it cant cast the value,
i put it in startercharacterscripts and it doesnt error me the animation just doesnt work.

LoadAnimation needs an animation object with the ID, and not just the ID itself. You have to insert an Animation instance and change the AnimationId property to rbxassetid://YOURIDHERE. Then in the LoadAnimation function, do:

local animTrack = humanoid:LoadAnimation(AnimationInstanceHere)

like this rbxassetid://4473996043?