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.
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 | local Tool = script.Parent |
04 | local RemoteEvent = script.Parent:WaitForChild( "RemoteEvent" ) |
05 |
06 | Tool.Activated:Connect( function () |
07 | if Mouse.Target then |
08 | RemoteEvent:FireServer(Mouse.Target) |
09 | end |
10 | end ) |
Then, we have the regular script for when the RemoteEvent activates.
01 | local RemoteEvent = script.Parent:WaitForChild( "RemoteEvent" ) |
02 | local TargetTorso = nil |
03 | local Using = false |
04 |
05 | RemoteEvent.OnServerEvent:Connect( function (player, part) |
06 | if part:FindFirstChildOfClass 'Humanoid' then |
07 | local anim = Instance.new( "Animation" ) |
08 | anim.Parent = part |
09 | anim.AnimationId = "rbxassetid://5336538893" |
10 | anim:Play() |
11 | end |
12 |
13 | 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.
01 | local RemoteEvent = script.Parent:WaitForChild( "RemoteEvent" ) |
02 | local TargetTorso = nil |
03 | local Using = false |
04 |
05 | RemoteEvent.OnServerEvent:Connect( function (player, part) |
06 | local Character = player.Character |
07 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
08 | if part:FindFirstChildOfClass 'Humanoid' then |
09 | local anim = Instance.new( "Animation" ) |
10 | anim.Parent = part |
11 | anim.AnimationId = "rbxassetid://5336538893" |
12 |
13 | local animtrack = Humanoid:LoadAnimation(anim) |
14 | animtrack:Play() |
15 | end |
16 |
17 | 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).
1 | if Part.Parent:FindFirstChildOfClass( 'Humanoid' ) then |