I made a script that gives a player a custom walk animation in a certain part of the game, afterwards, when the player touches a part, the custom walk animation gets destroyed.
However, the script isn’t working and the animation still plays whenever the player walks. Am I doing something wrong?
custom walk animation script
workspace.Checkpoints["26"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent == script.Parent and not gb2 then
gb2 = true
local walkanim = script:WaitForChild("Run")
local walkanimtrack = humanoid.Animator:LoadAnimation(walkanim)
humanoid.Running:Connect(function(speed)
if speed > 0 then
if not walkanimtrack.IsPlaying then
walkanimtrack:Play()
end
else
if walkanimtrack.IsPlaying then
walkanimtrack:Stop()
end
end
end)
workspace.FunctionParts.FunctionPart15.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent == script.Parent and not gb3 then
gb3 = true
walkanimtrack:Destroy()
wait()
end
end)
end
end)