Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

just use this as a normal script

1 answer

✓ Accepted answer

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)

1 comment

0

No explanation ...

This discussion is preserved as it was. New answers, comments, and votes are closed.