This is a section of a script for a round system.

local roundlength = map:FindFirstChild("Time").Value
		local canwin = true
		local playingchars = ingame:GetChildren()
		local gameongoing = game.Workspace.GameOngoing
		gameongoing.Value = true
		if map:FindFirstChild("Genre").Value == "Survival" then
			if map:FindFirstChild("Game") then
				map:FindFirstChild("Game").Disabled = false
			end
			local gamescript = map:FindFirstChild("Game")
			repeat
				wait(1)
				roundlength = roundlength - 1
			until #playingchars == 0 or roundlength == 0
			gameongoing.Value = false
			gamescript.Disabled = true
			if #playingchars == 0 and roundlength > 0 then
				message.Value = "Nobody survived!"
				wait(5)

This part of the script is supposed to end the round when everyone is dead. The "playingchars" variable is all of the character models in the ingame folder ie. the players that are alive and playing the round. The "gamescript" variable is the script inside the map which controls the round and allows for it to work. The "roundlength" variable is the length of the round which counts down until either everyone is dead (the number of playingchars is 0) or until it reaches 0, at which point the gamescript is disabled.

The condition at the bottom is meant to be met which all players are dead and there is still time remaining, however after testing it multiple times, the round simply continues after I die.

I made a similar script for a similar game a while back and it worked fine:

if map:FindFirstChild("Type").Value == "Survival" then 
			if map:FindFirstChild("Game") then
				map:FindFirstChild("Game").Disabled = false
			end
			message.Value = "Time left: "..roundlength
			wait(1)
			repeat
				roundlength = roundlength - 1
				message.Value = "Time left: "..roundlength
				wait(1)
			until roundlength == 0 or #ingame:GetChildren() == 0
			if map:FindFirstChild("Game") then
				map:FindFirstChild("Game").Disabled = true
			end
			if #ingame:GetChildren() == 0 and roundlength > 0 then
				map:Destroy()
				message.Value = "No one won :("
				wait(3)

Not too sure what I'm doing wrong here.

1 comment

0

Could you possibly provide more of the code so I can help you better?