I'm making a prop hunt game, and I want it so when the prop value reaches 0, the while true do loop stops and goes from the top again and starts a new round.
I'm getting really confused with these terms like "Return" and "Break"
; I know what they are, I just don't know how or where to use them so some help would be really helpful.
Here is the code - I want the script to break out of the playgame() function and start the next one in the while loop.
HIGHLIGHTED AREAS:
Function: Line 21 - Line 38
While Loop: 109-117
local lobbylocation = workspace.Lobby.Lobby.Position + Vector3.new(0, 3, 0)
local gamelocation = workspace.Maps.Main.Position + Vector3.new(0, 3, 0)
local replicatedstorage = game:GetService("ReplicatedStorage")
local timeevent = replicatedstorage:WaitForChild("TimeEvent")
local propcount = replicatedstorage.PropCount
wait(3)
print("everything loaded")
game.Players.PlayerAdded:Connect(function(plr)
plr.Team = game.Teams.Lobby
replicatedstorage.ServerCount.Value += 1
end)
game.Players.PlayerRemoving:Connect(function()
replicatedstorage.ServerCount.Value -= 1
end)
wait(1)
local function playgame()--300
local timeAmount = 20
local timerText = "Time Left: "
while timeAmount > 0 and replicatedstorage.PropCount ~= 0 do
timeevent:FireAllClients(timeAmount, timerText)
wait(1)
timeAmount -= 1
if replicatedstorage.PropCount == 0 then
print("HUNTERS WIN")
break
end
if timeAmount == 0 then
print("PROPS WIN")
break
end
end
end
local function playintermission()
local intermission = 10--60
local timerText = "Intermission: "
while intermission > 0 do
timeevent:FireAllClients(intermission, timerText)
wait(1)
intermission -= 1
end
end
local function resetplayers()
for _, plr in pairs (game.Players:GetChildren()) do
plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbylocation)
end
end
local function teleportplayers()
for _, plr in pairs (game.Players:GetChildren()) do
local huntercount = replicatedstorage:WaitForChild("HunterCount")
if huntercount.Value <= 0 then
huntercount.Value += 1
plr.Character.PlayerTeam.Value = "Hunters"
plr.Character.HumanoidRootPart.CFrame = CFrame.new(gamelocation)
plr.Team = game.Teams.Hunters
else
propcount.Value += 1
plr.Character.PlayerTeam.Value = "Props"
plr.Character.HumanoidRootPart.CFrame = CFrame.new(gamelocation)
plr.Team = game.Teams.Props
end
end
end
local function resetall()
for _, plr in pairs(game.Players:GetChildren()) do
local huntercount = replicatedstorage:WaitForChild("HunterCount")
huntercount.Value = 0
propcount.Value = 0
plr.Character.Humanoid.Health = 0
plr.Team = game.Teams.Lobby
if plr.Team == game.Teams.Hunters then
local propgun = plr:FindFirstChild("PropGun") or plr.Character:FindFirstChild("PropGun")
if propgun then
propgun:Destroy()
end
end
end
end
local function hunterwait()
for _, plr in pairs (game.Players:GetChildren()) do
if plr.Team == game.Teams.Hunters then
local hunterscreen = plr.PlayerGui:WaitForChild("HunterScreen")
hunterscreen.Enabled = true
wait(5)
hunterscreen.Enabled = false
local propgun = replicatedstorage:WaitForChild("PropGun")
local gunclone = propgun:Clone()
gunclone.Parent = plr.Backpack
end
end
end
while true do
resetplayers()
playintermission()
teleportplayers()
hunterwait()
playgame()
print("GAME OVER")
resetall()
end

12 comments
Umm why would you want to break out of a function, you normally break out of loops..
I'm new to round systems and stuff, and I just want it so that when the propcount value reaches 0 it moves onto the resetall() function, and I have no idea how.
why do u have a while true do at the end im confused
so that it plays the round over and over again - it's a prophunt game. all i want is that when the props all get killed or when the hunters run out of time that the loop plays from the start but idk how to make it restart
Hi thanks for your comment, are there any errors?
no errors but it's still not working, i added prints and theyre not activating (after it says if propcount == 0 then i added a print and when it does equal zero it never does anything or prints anything)
so it doesnt even print hunters win and stuff?
nope nothin
well that means your script isnt coded correctly
well shit lol
Hi can you add me to team create so i can try solve this
sure thing