Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

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

Asked by 3 months 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 24 — 3mo
1
how to delete another persons comment botw_legend 452 — 3mo

Closed as Not Constructive by Brandon1881, LennyPlayzYT, Cynical_Innovation, KBRM101, 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 3 months 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 460 Moderation Voter
3 months 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)