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

how to make the first person who joins the server run the playeradded function?

so i am making a game and the playeradded needs to run for the first person who joins the game how do i make that happen?

2 comments

1

Just so you know, playeradded is an event.

1

how to delete another persons comment

2 answers

✓ Accepted answer

I would recommend using conditional statements along the lines of something like this

local function foo()
	if #game.Players == 1 then
		-- code here
	else
		return
	end
end

game.Players.PlayerAdded:Connect(foo)

From what I can gather, you are trying to run the playeradded event in a local script, hence you are somewhat stating that it isn't running for the first person. This cannot be done as the player is added before the contents of the script are fired.

If for whatever reason you need something to be done on the client through a playeradded event, i'd suggest using a server script, and then firing a remote event to the client.

Server

game:GetService("Players").PlayerAdded:Connect(function(player)
	game.ReplicatedStorage.PlayerJoined:FireAllClients(player)
end)

Local

local event = game:GetService("ReplicatedStorage"):WaitForChild("PlayerJoined")

event.OnClientEvent:Connect(function(playerWhoJoined)
	--your code here

end)

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