Hello Developers!
So I’m making a minigame, it was all working until I put in another minigame.
The issue is the timer is not working because the repeat until is not running at all
there is also no error at all
CODE:
local s = script.Stat
local maps = game.ReplicatedStorage.Maps:GetChildren()
local rand = math.random(1, #maps)
local map = maps[rand]:Clone()
t = 0
while true do
t = 15
repeat
t = t-1
s.Value = "Intermission "..t
wait(1)
until t == 0
s.Value = "Game Starting!"
wait(1)
map.Parent = workspace
s.Value = "We'll be playing "..map.Name
wait(3)
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
local spawnLocation = math.random(1,#workspace.Spawns:GetChildren())
local spawnLocation2 = math.random(1,#workspace.Spawns2:GetChildren())
if map.Name == "Obby" then
players[i].Character:MoveTo(workspace.Spawns2:GetChildren()[spawnLocation2].Position)
players[i].Character.Parent = workspace.Ingame
else
if map.Name == "Mountain Over Flow!" then
players[i].Character:MoveTo(workspace.Spawns2:GetChildren()[spawnLocation].Position)
players[i].Character.Parent = workspace.Ingame
else
players[i].Character:MoveTo(workspace.Spawns:GetChildren()[spawnLocation].Position)
players[i].Character.Parent = workspace.Ingame
end
end
end
end
end
local roundLength = 120
local canWin = true
local roundType = ""
if map:FindFirstChild("Obby") then
roundType = "Obby"
map.Endpart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and canWin == true then
canWin = false
s.Value = hit.Parent.Name.." has won!"
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +10
end
end)
elseif map:FindFirstChild("Snowball") then
roundType = "Snowball"
local children = workspace.Ingame:GetChildren()
for i = 1,#children do
map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
end
map:FindFirstChildWhichIsA("Tool"):Destroy()
end
if map:FindFirstChild("Mountain Over Flow!") then
roundType = "Mountain Over Flow!"
map.Endpart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and canWin == true then
canWin = false
s.Value = hit.Parent.Name.." has won!"
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +10
end
end)
end
repeat
roundLength = roundLength -1
s.Value = "Time Left: "..roundLength
wait(1)
until roundLength == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0 or (#workspace.Ingame:GetChildren() == 1 and roundType == "Snowball")
if #workspace.Ingame:GetChildren() == 1 and roundType == "Snowball" then
local char = workspace.Ingame:FindFirstChildWhichIsA("Model")
s.Value = char.Name.. " has won"
local plr = game.Players:GetPlayerFromCharacter(char)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +10
end
wait(.5)
map:Destroy()
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i]:LoadCharacter()
end
end
THE CODE THAT IS NOT RUNNING
repeat
roundLength = roundLength -1
s.Value = "Time Left: "..roundLength
wait(1)
until roundLength == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0 or (#workspace.Ingame:GetChildren() == 1 and roundType == "Snowball")
please note before i added the minigame everything was working.
The new minigame is Mountain overflow
repeat
roundLength = roundLength -1
s.Value = "Time Left: "..roundLength
task.wait(1)
until roundLength == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0 or (#workspace.Ingame:GetChildren() == 1 and roundType == "Snowball")
You also might want to break the while loop when it is done.
Sadly it does not work
When the minigame starts it starts the intermission again
Do you break the loop when it is done? (Otherwise, it will run always, unless the loop returns false.)
The thing is it wont run, I tried adding a print to see if it is looping but its not
The loop? If so, it’s something else in the code. I will overview it, and let you know if anythings wrong!
Try using task.wait() for ANY waits in the script!
Aright i will try that thanks.
Check out the Task Library for more info on tasks! It is extremely helpful in a lot of instances.
noooooo it does not work i used taskt.wait() but it does the same thing
Okay. So it is a problem early on. The code looks good, so I have no idea what is going on. I unfortunately don’t know that problem, try using prints to find when it stops, then go from there. I could be able to help you with it then.
Alright so i placed some prints (“hello”) and those dont seem to print
local s = script.Stat
local maps = game.ReplicatedStorage.Maps:GetChildren()
local rand = math.random(1, #maps)
local map = maps[rand]:Clone()
t = 0
while true do
t = 15
repeat
t = t-1
s.Value = "Intermission "..t
task.wait(1)
until t == 0
s.Value = "Game Starting!"
task.wait(1)
map.Parent = workspace
s.Value = "We'll be playing "..map.Name
task.wait(3)
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
local spawnLocation = math.random(1,#workspace.Spawns:GetChildren())
local spawnLocation2 = math.random(1,#workspace.Spawns2:GetChildren())
if map.Name == "Obby" then
players[i].Character:MoveTo(workspace.Spawns2:GetChildren()[spawnLocation2].Position)
players[i].Character.Parent = workspace.Ingame
else
if map.Name == "Mountain Over Flow!" then
players[i].Character:MoveTo(workspace.Spawns2:GetChildren()[spawnLocation].Position)
players[i].Character.Parent = workspace.Ingame
else
players[i].Character:MoveTo(workspace.Spawns:GetChildren()[spawnLocation].Position)
players[i].Character.Parent = workspace.Ingame
end
end
end
end
end
local roundLength = 120
local canWin = true
local roundType = ""
if map:FindFirstChild("Obby") then
roundType = "Obby"
map.Endpart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and canWin == true then
canWin = false
s.Value = hit.Parent.Name.." has won!"
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +10
end
end)
print("hello")
elseif map:FindFirstChild("Snowball") then
roundType = "Snowball"
local children = workspace.Ingame:GetChildren()
for i = 1,#children do
map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
end
map:FindFirstChildWhichIsA("Tool"):Destroy()
end
if map:FindFirstChild("Mountain Over Flow!") then
roundType = "Mountain Over Flow!"
map.Endpart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and canWin == true then
canWin = false
s.Value = hit.Parent.Name.." has won!"
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +10
end
end)
end
print("hello")
repeat
roundLength = roundLength -1
s.Value = "Time Left: "..roundLength
task.wait(1)
until roundLength == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0 or (#workspace.Ingame:GetChildren() == 1 and roundType == "Snowball")
if #workspace.Ingame:GetChildren() == 1 and roundType == "Snowball" then
local char = workspace.Ingame:FindFirstChildWhichIsA("Model")
s.Value = char.Name.. " has won"
local plr = game.Players:GetPlayerFromCharacter(char)
plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +10
end
task.wait(.5)
map:Destroy()
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i]:LoadCharacter()
end
end
Like nothing whatsoever? This text will be blurred
Yeah the print("hello")
does not show
Is t a global variable? Make it a local variable. (local t = 0
)
I believe this is because there is script after the loop and because it is a “while true do” it happens “If you’re running a loop that won’t typically end, such as an infinite while true do
loop, you can force it to end with the break
command so the script can continue running the code following it” Loops (roblox.com)
I am not a genius scripter but I believe you could also separate it into multiple scripts.
So where would i place the break?