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

What function would be best to add a player in?

Like when a player is added or respawned?

1 answer

✓ Accepted answer

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

3 comments

0

Wow, that's a lot for playersadded, looks a bit too much, I'll try using :GetPlayers(), thanks!

0

Also is it possible to get the character like player.Character and get the PlayerGui like player.PlayerGui?

0

Yes.

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