When I try to make a round system (like mad murderer, phantom forces, ect.) I always get lost on how to make it a continuous loop. I am pretty sure while loops and repeats are useful when making these types of scripts but I need a little help on how I could do this.
Here is one of my unfinished scripts.
local gameFolder = game.ReplicatedStorage.Game
local events = game.ReplicatedStorage.Events
local playersInMatch = gameFolder.PlayersInGame
local currentTime = gameFolder.CurrentTime
local playersInServer = gameFolder.Players
local gameInProgress = gameFolder.GameInProgress
minimumPlayers = 4
xpReward = 10
creditsReward = 5
intermissionTime = 45
gameTime = 120
playersInServer.Changed:Connect(function()
if playersInServer.Value >= minimumPlayers then
while playersInServer.Value < minimumPlayers do
wait(1)
end
currentTime.Value = intermissionTime
repeat currentTime.Value = currentTime.Value - 1
wait(1)
until playersInServer.Value < minimumPlayers or currentTime.Value == 0
--Start Game
if currentTime.Value == 0 and playersInServer.Value >= minimumPlayers then
events.GameStart:FireAllClients()
local player = game.Players:GetChildren()
for i = 1, #player do
if player.Stats.AFK.Value == false then
local playerTag = Instance.new("StringValue")
playerTag.Value = player.Name
playerTag.Parent = gameFolder.PlayerList
playersInMatch.Value = playersInMatch.Value + 1
player.Character.Humanoid.Torso.CFrame = CFrame.new(0,3,0)
player.Character.Humanoid.WalkSpeed = 20
player.Character.JumpPower = 40
player.InGame.Value = true
end
wait(5)
local player = game.Players:GetChildren()
for i = 1, #player do
player.Character.FF:Destroy()
end
currentTime.Value = gameTime.Value
gameInProgress.Value = true
end
end
else
return
end
end)
--Win
playersInMatch.Changed:Connect(function()
if playersInMatch.Value == 1 and gameInProgress.Value == true then
playersInMatch.Value = 0
local player = game.Players:GetChildren()
for i = 1, #player do
if player.InGame.Value == true then
player.Stats.XP.Value = player.Stats.XP.Value + xpReward
player.Stats.Credits.Value = player.Stats.Credits.Value + creditsReward
events.Win:FireAllClients(player.Name)
else
player.Stats.XP.Value = player.Stats.XP.Value + 1
end
end
wait(5)
events.Reset:FireAllClients()
end
end)
As you can see it is very unorganized and doesn't even loop. I understand how to teleport characters, reward people, and all that stuff. It seems simple when I think of it but once i start scripting everything gets unorganized and confusing. If anyone could possibly give me a simplified example or a list that'd be great. Thank you.

1 comment
lastTick = tick() while true do wait() print(lastTick-tick()) end -- now all u gotta do is turn it into a timer interface..