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

Why doesn't my animation play after the remote event has been fired?

Asked by 5 years ago

Basically I made a script so that when the remote is fired, it finds the player who fired it and plays an animation on them. For some reason it doesn't work and nothing shows up in the output.

local LA = game.ReplicatedStorage.LightAttack
local HA = game.ReplicatedStorage.HeavyAttack
local swordanim = game.ReplicatedStorage.Animation1

LA.OnServerEvent:Connect(function(plr)
local player = plr
local char = player.Character or player.CharacterAdded:Wait()
local hum = plr:WaitForChild('Humanoid', 10000)
local anim = hum:LoadAnimation(swordanim)
anim:Play()
print'works'
end)

HA.OnServerEvent:Connect(function(plr)
local name = plr.Name
local player = game.Workspace:FindFirstChild(name)
local hum = player:FindFirstChild('Humanoid')
end)

1 answer

Log in to vote
0
Answered by
Kymaraaa 116
5 years ago
Edited 5 years ago

It's not working as you're waiting 10,000 seconds for the Humanoid to appear in the Player. The Humanoid is located in the Character. I'd recommend not doing :WaitForChild(Child, time) as like you've just encountered, your code won't error even though it's wrong because it first has to wait 10,000 seconds just in-case it loads in the Player which it never will.

I've fixed the code for you.

local LA = game.ReplicatedStorage.LightAttack
local HA = game.ReplicatedStorage.HeavyAttack
local swordanim = game.ReplicatedStorage.Animation1
LA.OnServerEvent:Connect(function(plr)
    local player = plr
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char:WaitForChild('Humanoid')
    local anim = hum:LoadAnimation(swordanim)
    anim:Play()
    print'works'
end)
HA.OnServerEvent:Connect(function(plr)
    local name = plr.Name
    local player = game.Workspace:FindFirstChild(name)
    local hum = player:FindFirstChild('Humanoid')
end)
Ad

Answer this question