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

How do I check if a player is in game.players by username?

Asked by
u1v6 22
4 years ago

I'm trying to check if a player exists in game.players with their username, how would I go about doing this?

0
if game.Players:FindFirstChild(USERNAME) then mybituploads 304 — 4y
0
A better way of doing it is by looping and checking if a player is in a table. JesseSong 3916 — 4y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Make a table of the list of people you want then loop through The below code should work.

game.Players.PlayerAdded:Connect(function(player)
local tab = { "Player1"," Player2"} -- list of people you want
for i,v in pairs(tab) do
if player.Name == v then
print ("player is in game")
end
end
end)
Ad

Answer this question