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

My player existence check not printing anything?

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.

1 answer

✓ Accepted answer

There is really no need to use a 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.

##Resources:

PlayerAdded

PlayerRemoving


##Accept and upvote if this helps!

1 comment

0

I was trying to figure out how it worked to make another script of mine not break when someone left, I will let you know if this works!

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