I’m trying to make an effect where when you run into a log, you trip. I made a falling animation and made a script that makes it play when you hit a log but it’s not working. The animation just doesn’t play, even though it’s definitely the currect Id.
Here’s the script:
Log.Touched:Connect(function(hit)
print("Hello") -- it prints
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
Player.Character.Humanoid:LoadAnimation(Player.Character.Animation):Play()
end
end)
I have no idea why this doesn’t work, there were no errors in the output.
local Hits = {}
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
if Hits[player.UserId] then return end
Hits[player.UserId] = true
local Animation = Player.Character.Humanoid:LoadAnimation(Player.Character.Animation)
Animation.AnimationPriority = Enum.AnimationPriority.Action -- Ideally you should set this in the Animation Editor because it won't replicate otherwise.
Animation:Play()
Animation.Stopped:Connect(function()
Hits[player.UserId] = nil
end
end
You may want to also stop the player from moving when tripped too, but it’s up to you.