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

What function would be best to add a player in?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

Like when a player is added or respawned?

1 answer

Log in to vote
1
Answered by
Wutras 294 Moderation Voter
8 years ago

The events .PlayerAdded and .PlayerRemoving are used like this:

players = {}
function RemoveFromTable(thetable, toberemoved) -- That's a function I made due to no such function existing.
    if thetable == nil then
        error("ERROR | FIRST ARGUMENT/TABLE IS NIL | FUNCTION: RemoveFromTable")
    end
    if thetable == nil then
        error("ERROR | SECOND ARGUMENT/OBJECT IS NIL | FUNCTION: RemoveFromTable")
    end
    local istoberemovedintable = false
    for _, yesorno in pairs(thetable) do
        if yesorno == toberemoved then
            istoberemovedintable = true
        end
    end
    if istoberemovedintable == false then
        error("ERROR | SECOND ARGUMENT/OBJECT IS NOT IN TABLE | FUNCTION: RemoveFromTable")
    end
    for i = 1/table.getn(thetable), table.getn(thetable) do
        if thetable[i*table.getn(thetable)] == toberemoved then
            table.remove(thetable, i*table.getn(thetable))
        end
    end
end

game.Players.PlayerAdded:connect(function(plr)
    table.insert(players, plr)
end)
game.Players.PlayerAdded:connect(function(plr)
    RemoveFromTable(players, plr)
end)

But an easier way would be to just use the :GetPlayers() function. Like this:

players = game.Players:GetPlayers()
0
Wow, that's a lot for playersadded, looks a bit too much, I'll try using :GetPlayers(), thanks! yoshi8080 445 — 8y
0
Also is it possible to get the character like player.Character and get the PlayerGui like player.PlayerGui? yoshi8080 445 — 8y
0
Yes. Wutras 294 — 8y
Ad

Answer this question