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

How do I check if player left?

I've asked questions about the same script, but this is a different section. Previously a kind samaritan helped me find a random player and have the ability to change values in the player, but I cannot detect if the player left the game so I can wrap up the game.

-- This selects the player "p[selected_value]"
local plrs = game:GetService("Players")
local p = plrs:GetPlayers()
local selected_value = math.random(1,#p)
p[selected_value].Settings.Tagger.Value = true

I tried checking if the player is nill, but that had no outcome

local waiting = 30 -- amount of time to count down from
for y = 1,waiting + 1 do -- this makes it stop at 1
	wait(1)
	if p[selected_value].Settings.Tagger.Value == true then -- checks if he is tagger, if not he has died. 
		main.MainText("Time remaining: "..waiting) -- calls a module script to change GUI
		waiting = waiting-1 -- decreases amount of time left 
	elseif if p[selected_value] == nil then -- checks if the 'tagger' left
		main.MainText("The Player has left.")  -- calls a module script to change GUI
		wait(2)
		break -- breaks the loop, thus ending the game. 
end

1 answer

✓ Accepted answer

game.Players.PlayerRemoving:Connect(function) --- Code goes here end)

5 comments

0

How would I detect it in this script :/

0

I don't know what you are trying to accomplish so If you give that I can thoroughly help

0

Im running a count down, and every second it checks if the player has died and if so, it breaks to loop to end the game

0

You could set a boolean value like taggerLeft = false, then when the event fires you could say taggerLeft = true, and then your code could check the true/false on each loop cycle to branch to other logic.

0

I didn't think of that, Thanks!

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