Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)
0
why repost lol Gooncreeper 98 — 3y
0
Try checking if your event is being fired by using a print statement mcslimeman 37 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

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

Ad
Log in to vote
0
Answered by 3 years ago

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

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

Answer this question