Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't the player do the animation? (REPOST)

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)

2 comments

0

why repost lol

0

Try checking if your event is being fired by using a print statement

2 answers

✓ Accepted answer

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

1 comment

0

Your answer helped too, thank you. But I accepted the other person's because he responded literally a single minute quicker.

This discussion is preserved as it was. New answers, comments, and votes are closed.