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.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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 = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=3454180452" end end)

Please help!

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

1 answer

Log in to vote
0
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")

script.Parent.Touched:Connect(function(hit)
    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)
        humanoid_animation:Play()
    end
end)
Ad

Answer this question