How can I get my script and local script to communicate?

I have a tool that I want to play an animation when it’s clicked, but the script is coded in a way that it will work on the server side. With some research, I discovered that only local scripts can play an animation for a local player.
I’ve tried using a remote event but it didn’t seem to work. Basically, I was just wanting a simple way for the script to send a message to the localScript to play the animation. Any help would be appreciated, thanks!

Animations replicate to all clients, if done correctly.

1 Like

Okay, do you know how I could go about that?

If the animation is playing, it is being replicated to all clients - everyone will be able to see it.

Right, but that’s not really the issue. I made this script for a localscript on my tool, and it doesn’t work on a normal script.

local tool = script.Parent
local anim = tool:WaitForChild('Animation')
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild('Humanoid')
local loadanim = humanoid:LoadAnimation(anim)

tool.Activated:Connect(function()
	loadanim:Play()
end)

Either I was wondering how this could be rescripted to work on a normal script, or find a way for the normal script to send a message to the local script that could play the animation

1 Like
local tool = script.Parent
local anim = tool:WaitForChild('Animation')

tool.Activated:Connect(function()
	local Character = tool.Parent
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	
	local AnimationTrack = Animator:LoadAnimation(anim)
	AnimationTrack:Play()
end)

Try this with a server-script.

2 Likes

Well that works perfectly. Thank you so much :grinning:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.