How do I make this animation visible to everyone?

Hello,

I’ve been making a flashlight with the help of a friend, but I ran into one issue… The Flashlight Animation doesn’t play for everyone…

Now, the Script is Local, I understand that, but I tried making it a normal script (inside of the tool), won’t work though, for obvious reasons.

I tried tinkering around with the locals, but it only seems to break the animation.

I am utter garbage at scripting, how could I convert this to a normal script, to make the animation play for everyone in the server?

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script.Parent.Wave)

--

script.Parent.Equipped:Connect(function()
	anim:Play()
end)

script.Parent.Unequipped:Connect(function()
	anim:Stop()
end)

Thank you for any tips/hints on how I could make this work for everyone.

PS: I’m guessing RemoteEvents have to be used in this case? No idea, as I said, I’m garbage at scripting…

PPS:
a

1 Like

Basically what I think is happening here is that you loaded the animation before the animator even replicated from the server to your client. When you don’t have the animator object, it won’t replicate to the server.

From DevHub:

Both Humanoid:LoadAnimation() and AnimationController:LoadAnimation() will create an Animator if one does not already exist. When calling LoadAnimation from LocalScripts you need to be careful to wait for the Animator to replicate from the server before calling LoadAnimation if you want character animations to replicate. You can do this with WaitForChild(“Animator”).

You need to wait for an Animator descendant before you load the animation.

3 Likes

So that means it doesn’t matter if it’s a local script or not?

2 Likes

Yep. You can do it from a server script but it’s usually done through local scripts.

2 Likes

As I said, I’m garbage at scripting, so basically where do I have to put the WaitForChild(“Animator”)?

1 Like

You can do it anywhere before the line that loads teh animation, you just need to have the humanoid. I’d put it right after you get the humanoid.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
hum:WaitForChild("Animator")
local anim = hum:LoadAnimation(script.Parent.Wave)

--

script.Parent.Equipped:Connect(function()
	anim:Play()
end)

script.Parent.Unequipped:Connect(function()
	anim:Stop()
end)
3 Likes

Are you using team create? Just want to make sure because there is another reason why its not working. Also can you only see it?

2 Likes

Thank you, let me just try this real quick.

1 Like

Yes, the game itself is owned by my friend, I’m just developing for him. When I start the testing with 2 players, it only appears for me.

1 Like

Wowzers!
It works! Thank you so much man! Now I know how to make all of my other tools appear for all players :smirk:

2 Likes

I’m glad I helped you solve the issue

2 Likes

Here’s how my flashlight animation script sort of looks like.
I generally think it looks cleaner and easier to read and modify.
And the animation shows for everyone.

local tool = script.Parent
local player = game.Player.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()


local IdleAnimation = Instance.new("Animation")
IdleAnimation.AnimationId = "rbxassetid://1234567890"
local IA = character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(IdleAnimation)



tool.Equipped:Connect(function()
IA:Play()
2 Likes

Please mark @NeptuniaI’s reply as the solution if he has solved your problem.

3 Likes

Hey, sorry to bug you again!
I recently noticed that after I reset my character, the flashlight animation breaks, meanwhile output throws this at me:

08:59:57.067 Cannot load the AnimationClipProvider Service. - Client - IdleAnimator:5

I’ve seen other people complain about this recently, is there any fix to this?