How to check if a specific player if NOT in the game

It doesn’t work. :frowning:

		if Player.UserId == 3081295884 then
			print("Player found.  Hello, WolfieGamerYT!")
			local SpeedTool = ServerStorage.SpeedTool:Clone()
			SpeedTool.Parent = Player.Backpack
			print("tool given")
			
			local leaderstats = Player:WaitForChild("leaderstats")
			
			leaderstats.Coins.Value = 1000000
			leaderstats.Gems.Value = 1000000
		else
			local Humanoid = Character:WaitForChild("Humanoid")
			
				while task.wait(1) do
					Humanoid:TakeDamage(5)
					
				if Humanoid.Health == 0 then
					Player:Kick("Begone!")
					break
				end
			end
		end
	end)
end)
1 Like

Interesting. What exactly is and is not working? Can you show me screenshots of your output and what is happening during playtesting?

It’s not working because while task.wait(1) do keeps executing forever, and it never gets to the next part. I would reccomend setting up a Humanoid.Died:Connect(function()) before you start the while loop.

Can you please give me sample?

Ah, I see. I forgot to break the loop.

Try this.

local PlayerService = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

PlayerService.PlayerAdded:Connect(function(Player)
     if Player.UserId == 0000000000 --[[USER ID HERE]] then
          local SpeedTool = ServerStorage.SpeedTool:Clone()
          SpeedTool.Parent = Player.Backpack
          
          local Stats = Player:WaitForChild("leaderstats")
          
          Stats.Coins.Value = math.huge
          Stats.Gems.Value = math.huge
     else
          local Character = Player.Character
          local Humanoid = Character:WaitForChild("Humanoid")

          Humanoid.Died:Connect(function()
             Player:Kick("Be gone!")
          end

          while task.wait(1) do
             Humanoid:TakeDamage(5)
          end
     end
end

How to use Humanoid.Died:

local Humanoid = -- Path to humanoid here

local function Died()
     -- Function code here
end

Humanoid.Died:Connect(function(Died)

- or -

local Humanoid = -- Path to humanoid here

Humanoid.Died:Connect(function()
     -- Function code here
end
1 Like

It worked! Thank you so much! Have a good rest of your day! I just have one question: Would it still work if I removed the while loop?

The loop takes away 5 HP from the player every second. Here is a breakdown of it:

while task.wait(1) --[[1 Second interval]] do
     Humanoid:TakeDamage(5) -- Take 5 health points away
end -- End of the loop

So basically, the player will only be damaged by 5 if you take the loop away. They’ll never be killed.

You could, however, take away the loop and just instantly kill them instead.

Humanoid:TakeDamage(Humanoid.Health) -- Kills the player by taking all their HP
Player:Kick("Be gone!") -- Kicks the player

Alternatively, if you want them to die quicker, you can decrease the delay time or increase the amount of health you take away.

while task.wait(0.30) do
     Humanoid:TakeDamage(5)
end

- or -

while task.wait(1) do
     Humanoid:TakeDamage(20)
end

Hope this helps. Have a great rest of your day! :slightly_smiling_face:
Click here to learn more about loops!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.