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

Why my touchpart anim script doesnt want to work? (Local Script)

Asked by 6 years ago

i made a part touch script that when you touch the part the animation is going to start but it doesnt work heres my script:

local animation = Instance.new("Animation")
animation.AnimationId = "https://www.roblox.com/Asset?ID=01480845354"

local trackanimation = nil
local playability = true
function playanimation(AnimationSource)
    if playability==true then
        local plr = game.Players.LocalPlayer
        trackanimation = plr.Character.Humanoid:LoadAnimation(animation)

        trackanimation.KeyframeReached:connect(function(kf)
            print('Working')
        end)
        trackanimation:Play()
    end
end
script.Parent.Touched:connect(playanimation)
0
just use this as a normal script darkzerobits 92 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

It needs to be a normal script, then it works

Or if that doesn't work you could use this script, you need to insert an animation in the script for it to work

local Anim = script:WaitForChild("Animation")
local debounce = false

script.Parent.Touched:Connect(function(hit)
    if (not debounce) and hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid:FindFirstChild("Animator") and hit.Parent:FindFirstChild("HumanoidRootPart") then
        debounce = true
        local track = hit.Parent.Humanoid.Animator:LoadAnimation(Anim)
        track:Play()
        --particles! you can remove this if you want
local particles = Instance.new("Fire")
        particles.Parent = hit.Parent.HumanoidRootPart
        wait(2) -- set to how long you want the particles to last for
        particles.Enabled = false
        debounce = false
        wait(5)
        particles:Destroy()
    end
end)
0
No explanation ... User#24403 69 — 5y
Ad

Answer this question