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

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

Asked by 4 years ago

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?

1
Just so you know, playeradded is an event. Galvaric 39 — 4y
1
how to delete another persons comment botw_legend 502 — 4y

Closed as Not Constructive by Brandon1881, LennyPlayzYT, Cynical_Innovation, IAmNotTheReal_MePipe, Dovydas1118, and killerbrenden

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
1
Answered by 4 years ago

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)
Ad
Log in to vote
1
Answered by
Despayr 505 Moderation Voter
4 years ago

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)