Playing animations in table

I’m trying to play an animation that was inserted after being loaded in a function, however when i try to play it, i get the error attempt to call missing method 'Play' of table

local __REALANIMATIONS = {}
function __LOADANIMATION(__HUM: Humanoid?, __ANIM: Animator?)
	local __ANIMATIONS = {
		script:FindFirstChild("HITATTACK1")
		script:FindFirstChild("HITATTACK2")
	}
	
	if __HUM then
		if __HUM:FindFirstChild(__ANIM) then
			__ANIM:LoadAnimation(__ANIMATIONS)
			table.insert(__REALANIMATIONS, __ANIMATIONS)
		end
	end
end
LocalPlayer.CharacterAdded:Connect(function(__MODEL)
	__LOADANIMATION(__MODEL:FindFirstChildOfClass("Humanoid"), __MODEL:FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator"))
end)
function __INPUT(Input: InputObject?, ...)
	print(...)
	if Input == "RMB" then
		__REALANIMATIONS:Play()
	end
end

You are using :Play() on a table (__REALANIMATIONS) and not the humanoid.

Tried that and i got Unable to cast value to Object

try this

local __REALANIMATIONS = {}
function __LOADANIMATION(__HUM: Humanoid?, __ANIM: Animator?)
	local __ANIMATIONS = {
		script:FindFirstChild("HITATTACK1")
		script:FindFirstChild("HITATTACK2")
	}
	
	if __HUM then
		if __HUM:FindFirstChild(__ANIM) then
		       for i, v in _ANIMATIONS do
				__ANIM:LoadAnimation(v):Play()
				table.insert(__REALANIMATIONS, __ANIMATIONS)
                       end
		end
	end
end
LocalPlayer.CharacterAdded:Connect(function(__MODEL)
	__LOADANIMATION(__MODEL:FindFirstChildOfClass("Humanoid"), __MODEL:FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator"))
end)
function __INPUT(Input: InputObject?, ...)
	print(...)
	if Input == "RMB" then
		__REALANIMATIONS:Play()
	end
end

sorry for bad formating, my tabs doesnt works

u cant just use :Play() in the table because the table dont is an animation, so the solution is, make a for loop on the table and run the animations, i hope that this helped

Still Dosen’t work, What i’m trying to is load all animations in table when character spawns then play a random animation that was inserted.

ohh, so, u can do this:

local __REALANIMATIONS = {}
function __LOADANIMATION(__HUM: Humanoid?, __ANIM: Animator?)
	local __ANIMATIONS = {
		script:FindFirstChild("HITATTACK1");
		script:FindFirstChild("HITATTACK2");
	}

	if __HUM then
		if __HUM:FindFirstChild(__ANIM) then
			for i,v in __ANIMATIONS do
				table.insert(__REALANIMATIONS, __ANIM:LoadAnimation(v))
			end
		end
	end
end
LocalPlayer.CharacterAdded:Connect(function(__MODEL)
	__LOADANIMATION(__MODEL:FindFirstChildOfClass("Humanoid"), __MODEL:FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator"))
end)
function __INPUT(Input: InputObject?, ...)
	print(...)
	if Input == "RMB" then
		__REALANIMATIONS[math.random(1, #__REALANIMATIONS)]:Play()
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.