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

How would I do this?

I wanted to know how to make a part of a script where if all the players died then the round ends and resets the timer back to zero.

Round Code:

function roundCountdown()
    for roundMinute = 2,0,-1 do
        for roundSecond = 59,0,-1 do
            playerNotification('Time left!')
            playerCountdown(string.format("%d:%.2d",roundMinute,roundSecond))
            wait(1)
        end
    end
end

1 answer

game.Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function()
		local GameValue = Instance.new("BoolValue")
		GameValue.Parent = Player.Character
		GameValue.Name = "InGameValue"
	end)
end)

--The above adds in the "InGameValue" value every time the player spawns.


function CheckPlayers()
	local InGameNum = 0 --The number of players in game
	for _,v in pairs(game.Players:GetChildren())do --Scroll through players
		local Character = v.Character
		if Character then --Make sure the player's character is not nil
			local InGameValue = Character:FindFirstChild("InGameValue")
			if InGameValue and InGameValue == true then --Make sure the player's humanoid is not nil and health is above 0
				InGameNum = InGameNum + 1 --Add to the number of players alive
			else
				print(Player.."'s InGameValue not found")
			end
		else
			print(Player.."'s Character not found")
		end
	end
	if InGameNum == 0 then --Check to see if everyone is dead
		return false --Return that everyone is out of the game
	elseif InGameNum ~= 0 then
		return true --Return that someone is still in the game
	else 
		return nil
	end
end

function roundCountdown() 
    for roundMinute = 2,0,-1 do 
        for roundSecond = 59,0,-1 do 
            playerNotification('Time left!') 
            playerCountdown(string.format("%d:%.2d",roundMinute,roundSecond)) 
			local CheckInGame = CheckPlayers()
			if CheckInGame == false then
				roundSecond = 0
				--You may have to "break" after seting it to 0, I'm not sure.
			elseif CheckInGame == true then
				print("There are still people in the game")
			end
            wait(1) 
	   end 
    end 
end 

This code goes after you teleport the players:

--Assuming you already have the player under "game.players".
local PlayerInGameValue = player.Character.FindFirstChild("InGameValue")
if PlayerInGameValue  then
	PlayerInGameValue.Value = true
else
	print("Can not find: 'InGameValue'")
end

This should work, it does require you to set the value of "InGameValue" located in the player's character to true when you place him in a round though.

4 comments

0

It doesn't seem to work at all. It just skips to the end of the round once it round even starts. I was wondering how I could use it with IntValues. For example, if everybody's 'Playing' value is equal to zero then it ends the round.

0

Just edited it, It should work now. Remember to set the value of "InGameValue" to true when the players enter a round/minigame.

0

Still not working, it does the same thing as before.

0

Did you set the "InGameValue" to true when the players entered a round?

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