I'm hitting the animation 256 limit. How do I fix this?

This is located in a server script. For most scripts I would be able to load the animation before hand, but how would I do that with a touch event? Since getting the humanoid has to be within the event wouldn’t I have to load the animationTrack within it as well?

wire.Touched:Connect(function(hit)
	local partParent = hit.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")


	if humanoid then
		local targetChar = humanoid.Parent
		if hit.Parent.Name ~= "Dummy" and not table.find(hitList,targetChar) then
			local zapTrack = game.ReplicatedStorage.PlayerAnimations.Zapped
			local zapAnimation = humanoid:WaitForChild("Animator"):LoadAnimation(zapTrack)

did you forget to play the animations?

local zapAnimation = humanoid:WaitForChild("Animator"):LoadAnimation(zapTrack)

zapAnimation:Play()

you can disconnect the event when the humanoid is detected using :Disconnect

youll need to have a variable for the event to disconnect it

like this

local ZapAnimation 
local Connection 
Connection = wire.Touched:Connect(function(hit)
	local partParent = hit.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		local targetChar = humanoid.Parent
		if hit.Parent.Name ~= "Dummy" and not table.find(hitList,targetChar) then
			Connection:Disconnect()
			local zapTrack = game.ReplicatedStorage.PlayerAnimations.Zapped
			ZapAnimation = humanoid:WaitForChild("Animator"):LoadAnimation(zapTrack)
		end
	end
end)

--// Example to get the zap anim thingy
ZapAnimation:Play()

you notice that i define again the event cuz

inside the event you cant get the variable so

I just didnt include the rest of the script since it doesn’t apply to my question

I’m playing the zap animation within the touched event. I can’t disconnect the event since it has to keep operating.

then youll need to store each loaded animations
animations should be loaded once

try

local StoredzapTracks = {}

wire.Touched:Connect(function(hit)
	local partParent = hit.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		local targetChar = humanoid.Parent
		if hit.Parent.Name ~= "Dummy" and not table.find(hitList,targetChar) then

			local zapAnimation = game.ReplicatedStorage.PlayerAnimations.Zapped
			
			if StoredzapTracks[targetChar] then
				StoredzapTracks[targetChar][zapAnimation]:Play()
			else
				StoredzapTracks[targetChar] = humanoid:LoadAnimation(zapAnimation)
				StoredzapTracks[targetChar][zapAnimation]:Play()
			end

		end
	end
end)

and btw why wont you just make a script each on the characters so you can just load the animation once easily without loading the animation inside the event

1 Like