Help on AdjustSpeed()

I have this script where it’s supposed to slow/faster animations from a NumberValue. This is a server script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,int)
	local hums = {}
	local anims = {}
	print(int)
	for _, hum in pairs(workspace:GetDescendants()) do
		if hum:IsA("Humanoid") or hum:IsA("AnimationController") then
			table.insert(hums,hum)
		end
	end
	for _, hum2 in pairs(hums) do
		table.insert(anims,hum2:GetPlayingAnimationTracks())
	end
	-- anims
	for _, anim in pairs(anims) do
		print(anim)
		anim:AdjustSpeed(int)
	end
	-- sound
	for _, sound in pairs(workspace) do
		if sound:IsA("Sound") then
			sound.PlaybackSpeed = int
		end
	end
end)

And sending the remote like this:

game:GetService("ReplicatedStorage").RemoteEvent:FireServer(Property)

Now, the output prints:

4 -- print(int)
-- and
 ▼  {
  [1] = Animation
} -- print(anim)

But I get this error:

ServerScriptService.Script:16: attempt to call a nil value

Where line 16 is

anim:AdjustSpeed(int)

Help?

That is a funny situation, I would explain if by, you are doing {}:AdjustSpeed(int) according to that error. My guess is you likely have a table within a table in that for loop.

I am confused. That’s the whole script, may you give me a line? There are 4 loops. Heh

Where you put print(anim) prints a table. Line 15.

This is what it prints. I am a noob with tables soo, I think this is an array. I don’t see the problem.

Yes, you see it is an array. print(anim) is a table, and right after you are doing anim:AdjustSpeed(int) same as {}:AdjustSpeed(int), does this make sense?

Well, it doesn’t. But in the loop, shouldn’t it focus on the animation object?

Well, hum2:GetPlayingAnimationTracks() is an array, and you inserted that array in anims. Therefore it created a table within a table.

And should I use table.unpack to it?

for _, animTable in pairs(anims) do
    for _, anim in pairs(animTable) do
		print(anim)
		anim:AdjustSpeed(int)
	end
end
1 Like

Actually not, I just got to test it.

ServerScriptService.Script:16: invalid argument #1 to ‘pairs’ (table expected, got Instance)

for _, animTable in pairs(anims) do
    if type(animTable) ~= "table" then continue end

    for _, anim in pairs(animTable) do
		print(anim)
		anim:AdjustSpeed(int)
	end
end