Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)????

0
put :GetChildren() after ls on line 5 greatneil80 2647 — 3y
0
its not doing anything now and it wont tell me why Jakob_Cashy 79 — 3y
0
After you put :GetChildren() after "Is", put print statements in your if statement then tell me if it's not printing. RichDiggerW189 2 — 3y
0
not printing Jakob_Cashy 79 — 3y

1 answer

Log in to vote
0
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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

0
there are no errors, but the number values arent being added. Jakob_Cashy 79 — 3y
Ad

Answer this question