So, try this. Use this LocalScript inside your tool.
local tool = script.Parent
local player = game.Players.LocalPlayer
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local toolAnimationEvent = replicatedStorage:WaitForChild(“ToolAnimationEvent”)
local function onEquipped()
toolAnimationEvent:FireServer("Equipped", tool)
tool.Activated:Connect(function()
local animation = tool:FindFirstChild("YourAnimation")
if animation then
local animator = tool:FindFirstChildOfClass("Animator")
if animator then
animator:LoadAnimation(animation):Play()
end
end
toolAnimationEvent:FireServer("PlayAnimation", tool)
end)
end
local function onUnequipped()
toolAnimationEvent:FireServer("Unequipped", tool)
end
tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)
And use this for ServerScriptService:
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local toolAnimationEvent = Instance.new(“RemoteEvent”)
toolAnimationEvent.Name = “ToolAnimationEvent”
toolAnimationEvent.Parent = replicatedStorage
toolAnimationEvent.OnServerEvent:Connect(function(player, action, tool)
if action == “PlayAnimation” then
– Broadcast to all other clients to play the animation
for _, otherPlayer in pairs(game.Players:GetPlayers()) do
if otherPlayer ~= player then
toolAnimationEvent:FireClient(otherPlayer, action, player, tool.Name)
end
end
elseif action == “Equipped” then
– Broadcast to all other clients that the tool is equipped
for _, otherPlayer in pairs(game.Players:GetPlayers()) do
if otherPlayer ~= player then
toolAnimationEvent:FireClient(otherPlayer, action, player, tool.Name)
end
end
elseif action == “Unequipped” then
– Broadcast to all other clients that the tool is unequipped
for _, otherPlayer in pairs(game.Players:GetPlayers()) do
if otherPlayer ~= player then
toolAnimationEvent:FireClient(otherPlayer, action, player, tool.Name)
end
end
end
end)
And last, use this in StarterPlayerScripts:
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local toolAnimationEvent = replicatedStorage:WaitForChild(“ToolAnimationEvent”)
toolAnimationEvent.OnClientEvent:Connect(function(action, player, toolName)
local character = player.Character
if character then
local tool = character:FindFirstChild(toolName)
if tool then
if action == “PlayAnimation” then
local animation = tool:FindFirstChild("YourAnimation")
if animation then
local animator = tool:FindFirstChildOfClass("Animator")
if animator then
animator:LoadAnimation(animation):Play()
end
end
elseif action == "Equipped" then
elseif action == "Unequipped" then
end
end
end
end)