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

What does my error mean by expecting table but got Instance?

the local script

local remote = game.ReplicatedStorage.Roll
local ls = game.Players.LocalPlayer.leaderstats:WaitForChild("Rolls")

game.ReplicatedStorage.Roll.OnClientEvent:Connect(function()
	for _, v in pairs (ls) do
		if v:IsA("IntValue") then
			v.Value += 1
		end
	end
	ls.Value = ls.Value + 1
end)

error on line 5: invalid argument #1 to 'pairs' (table expected, got Instance)????

4 comments

0

put :GetChildren() after ls on line 5

0

its not doing anything now and it wont tell me why

0

After you put :GetChildren() after "Is", put print statements in your if statement then tell me if it's not printing.

0

not printing

1 answer

Problem

You are attempting to iterate through an Instance instead of the required table.

The error itself means you are providing an Instance where you should be providing a table. The error also provides a location as to where you are providing an Instance instead of a table (line 5).

Solution

In your situation, using the :GetChildren() or :GetDescendants() methods will solve your issue as both of these methods return tables.

Code

local remote = game.ReplicatedStorage.Roll
local ls = game.Players.LocalPlayer.leaderstats:WaitForChild("Rolls")

game.ReplicatedStorage.Roll.OnClientEvent:Connect(function()
    for _, v in pairs (ls:GetChildren()) do -- Added :GetChildren()
        if v:IsA("IntValue") then
            v.Value += 1
        end
    end
    ls.Value = ls.Value + 1
end)

Conclusion

If you are confused by anything in this answer, or have more questions, feel free to contact me though my Discord server

1 comment

0

there are no errors, but the number values arent being added.

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