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

Why does this unpacked table show everything inside of the player?

A scripter on here improved my script and gave me this:

local Players = game:GetService("Players")

local function GetActiveRoles(Player)
    local ActiveRoles = {}
    local Stats = Player:WaitForChild("Stats")
    for _,Role in pairs(Stats:GetChildren()) do
        if Role.Value ~= false and Role.Name ~= "Coins" or  Role.Name ~= "Gems" then
            table.insert(ActiveRoles, Role.Name)
        end
    end
    print(unpack(ActiveRoles))
end

Players.PlayerAdded:Connect(GetActiveRoles)

I made some changes, and I simply don't understand, why the unpacked table shows me EVERYTHING inside of player, and not just every "role" that has been bought by the player (Booleans).

3 comments

0

Maybe move the Role.Value part to the other side of the or. Cause "or" separates the next parameter from all the previous ones, not just the one parameter before it. If you already know this, and already tried it, my apologies

0

Just check if the Role:IsA("BoolValue") and Role.Value ~= false then add it to the table

0

it doesn't print out anything.

1 answer

local Players = game:GetService("Players")

local function GetActiveRoles(Player)
    local ActiveRoles = {}
    local Stats = Player:WaitForChild("Stats")
    for _,Role in pairs(Stats:GetChildren()) do
        if Role:IsA("BoolValue") and Role.Value then -- check if it's a boolean value and true
            table.insert(ActiveRoles, Role.Name)
        end
    end
    print(unpack(ActiveRoles))
end

Players.PlayerAdded:Connect(GetActiveRoles)

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