Here is the script, it is a script in ServerScriptService.
while wait(1) do if game.Players:FindFirstChild("xXGokyXx") == nil then print('xXGokyXx is not here!') end if game.Players:FindFirstChild("xXGokyXx") ~= nil then print('xXGokyXx is here!') end end
It isn't printing anything when I go into team test and I'm not sure why.
while
loop for this problem. Instead, you can use several other methods.When a player joins the game, check if they are the player in question
To do this, we'll utilize the PlayerAdded
event of the Players
service.
local players = game:GetService("Players") local ExpectedPlayer = "xXGokyXx" players.PlayerAdded:Connect(function(player) if player.Name == ExpectedPlayer then print("xXGokyXx is here!") end end)
You can even match this up with the PlayerRemoving
event if you want to make a notification system or something of that nature.
local players = game:GetService("Players") local ExpectedPlayer = "xXGokyXx" players.PlayerAdded:Connect(function(player) if player.Name == ExpectedPlayer then print("xXGokyXx is here!") end end) players.PlayerRemoving:Connect(function(player) if player.Name == ExpectedPlayer then print("xXGokyXx is here!") end end)
Scan the Players service during runtime
If you want to scan the game during its runtime (i.e. not when a player joins like we did before), you can simply use the :FindFirstChild()
method like you did in your original code. Your code was technically fine, and it should have worked. You shouldn't use infinite while loops, though, unless you actually have to. My first code snippets shows a workaround for that.