So, nobody responded to the post about this that I made 9 hours ago, so here it is again.
Basically, I have a tool that is supposed to make a player do an animation when you click on them. (I hold the tool, and then click on a player. The player I click does an animation that I specified) But when I click on the other player, nothing happens.
First, there's this LocalScript in the tool.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Tool = script.Parent local RemoteEvent = script.Parent:WaitForChild("RemoteEvent") Tool.Activated:Connect(function() if Mouse.Target then RemoteEvent:FireServer(Mouse.Target) end end)
Then, we have the regular script for when the RemoteEvent activates.
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent") local TargetTorso = nil local Using = false RemoteEvent.OnServerEvent:Connect(function(player, part) if part:FindFirstChildOfClass'Humanoid' then local anim = Instance.new("Animation") anim.Parent = part anim.AnimationId = "rbxassetid://5336538893" anim:Play() end end)
You're problem in this script is not loading the animation. I have given you the new fixed script but please refer to the resource link I attached.
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent") local TargetTorso = nil local Using = false RemoteEvent.OnServerEvent:Connect(function(player, part) local Character = player.Character local Humanoid = Character:WaitForChild("Humanoid") if part:FindFirstChildOfClass'Humanoid' then local anim = Instance.new("Animation") anim.Parent = part anim.AnimationId = "rbxassetid://5336538893" local animtrack = Humanoid:LoadAnimation(anim) animtrack:Play() end end)
Resources: https://developer.roblox.com/en-us/articles/using-animations-in-games
Mouse.Target will return the exact part that you clicked on, not the model. You would end up wanting to check if the Humanoid is a valid member of the parent (character).
if Part.Parent:FindFirstChildOfClass('Humanoid') then