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

How do i fix script for part that changes characters animation?

Hello! The text below this message is a script that changes your avatar animations after you step on a part. I haven't really figured out what is causing the problems, but I think it has to do something with time delay between animations; example: if you jumped for a long period of time, an error will appear in output. I didn't say that I'm also new to scripting and bad at fixing stuff. So, does anyone have a solution about what a proper version should look like?

function onTouched(hit) 

	if hit.Parent:findFirstChild("Humanoid") ~= nil then
		local h = hit.Parent:findFirstChild("Humanoid")
		local anim = hit.Parent.Animate
		
		anim.run.RunAnim.AnimationId = "http://www.roblox.com/asset/?id="
		anim.climb.ClimbAnim.AnimationId = "http://www.roblox.com/asset/?id="
		anim.fall.FallAnim.AnimationId = "http://www.roblox.com/asset/?id="
		anim.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id="
		anim.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id="
		anim.jump.JumpAnim.AnimationId = "http://www.roblox.com/asset/?id="
		anim.swim.Swim.AnimationId = "http://www.roblox.com/asset/?id="
		anim.swimidle.SwimIdle.AnimationId = "http://www.roblox.com/asset/?id="
		anim.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id="
	end
end

script.Parent.Touched:connect(onTouched)

Output Error: AnimationTrack limit of 256 tracks for one Animator exceeded, new animations will not be played.

1 answer

✓ Accepted answer

There's no debounce! It will keep creating a new animation track and will reach a limit!

A simple fix would be:

local debounce = false

function onTouched(hit) 

	if debounce == false then
	    if hit.Parent:findFirstChild("Humanoid") ~= nil then
		debounce = true
	        local h = hit.Parent:findFirstChild("Humanoid")
	        local anim = hit.Parent.Animate
	
	        anim.run.RunAnim.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.climb.ClimbAnim.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.fall.FallAnim.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.jump.JumpAnim.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.swim.Swim.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.swimidle.SwimIdle.AnimationId = "http://www.roblox.com/asset/?id="
	        anim.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id="

		spawn(function()
			wait(5) -- You can change 5 to whatever you would like for when they can interact again
			debounce = false
		end)

		-- You can also remove the spawn(function() if you want the debounce to stay true forever
	    end
	end

script.Parent.Touched:connect(onTouched)

I also noticed that you never provided proper ID's.

3 comments

0

Also, if this would be multiplayer, you may need a more complicated script to make it so that two players can walk on it at the same time and not one of them not being able to get the animation.

0

Thank you for the script! Pretty much all i needed for it to work.

0

Your welcome!

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