New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

Animation upon Touched Part?

Asked by 3 months ago

If you sprint and start climbing on a Truss, you'll have increased walk speed. So whenever you sprint on the Truss, you have a different animation. Here's what I've got:

local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid local humanoid = player.Character.Humanoid

game.Workspace.Truss.Touched:Connect(function(p) if player.Character.Humanoid.WalkSpeed == 60 then
local anim ="Animation") anim.AnimationId = "" end end)

Please help!

AnimationTrack:Play() OnaKat 444 — 3mo
+ RemoteEvemt OnaKat 444 — 3mo

1 answer

Log in to vote
Answered by 3 months ago
Edited 3 months ago

From what I can tell, you're trying to use a Touched event for a Local Script. This won't work because touched events won't fire from the local script. You can set up the touched event from a server script. You don't need a local script because Humanoid:LoadAnimation()

Here is a written example:

This should be your server script.NOT a local script. Also, for this example, you would want to create a new Animation inside of the script. Remember to change the ID.

local animation script:WaitForChild("Animation")

    local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Just if you need the player.
    local humanoid = hit.Parent:FindFirstChild("Humanoid")

    if humanoid then
        local humanoid_animation = humanoid:LoadAnimation(animation)

Answer this question