Hi guys,
I wanted to make two scripts run at the same time. I have a script that is going to pick a random tower/obby and another timer script. Those scripts are separated so I added a wait(480) command on the random tower script and the timer is 8 minutes.
However, most of the time the random tower script runs first and so, it will regenerate the tower when the timer is still on 0:12 (or less or more). I used coroutines to make two scripts run at the same time.
However, it doesn’t fix the problem. Here’s the script I’ve used:
Script 1:
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local minutesvalue = rep:WaitForChild("Minutes")
local secondsvalue = rep:WaitForChild("Seconds")
local minutes = 8 --minutes
local seconds = 0 --seconds
local maps = game.ServerStorage.Maps:GetChildren()
local currentmap = workspace:WaitForChild("CurrentMap")
local chosenmap = script:WaitForChild("ChosenMap")
function chooseMap()
local choices = {} -- creates a table
for i = 1, #maps do
if maps[i]:IsA("Folder") then -- checks if it is a model
table.insert(choices, maps[i]) -- ads the maps to the table
end
end
local picked = math.random(#maps) -- picks a random map and then sets the chosenmap value to the maps name
chosenmap.Value = choices[picked].Name
end
function loadMap()
local map = game.ServerStorage.Maps:FindFirstChild(chosenmap.Value):Clone() -- clones the map determined from the chosenmap value
map.Parent = currentmap
end
function deleteMap()
for i,v in pairs(currentmap:GetChildren()) do
if v:IsA("Folder") then -- checks to see if the things in the currentmap folder is a model
v:Destroy() -- destroys it if it is a model
end
end
end
while true do
chooseMap()
loadMap()
wait(480)
deleteMap()
end
Script 2:
while true do
minutesvalue.Value = minutes
secondsvalue.Value = seconds
repeat
if secondsvalue.Value <= 0 then
minutesvalue.Value = minutesvalue.Value - 1
secondsvalue.Value = 59
else
secondsvalue.Value = secondsvalue.Value - 1
end
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
for _, v in pairs(game.Players:GetPlayers()) do
v.Character:WaitForChild("BeatObby").Value = false
local allplayers = players:GetPlayers()
for i, player in pairs(allplayers) do
wait(0.1)
player:LoadCharacter()
wait(0.1)
end
end
end
When combined:
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local minutesvalue = rep:WaitForChild("Minutes")
local secondsvalue = rep:WaitForChild("Seconds")
local minutes = 8 --minutes
local seconds = 0 --seconds
local maps = game.ServerStorage.Maps:GetChildren()
local currentmap = workspace:WaitForChild("CurrentMap")
local chosenmap = script:WaitForChild("ChosenMap")
function chooseMap()
local choices = {} -- creates a table
for i = 1, #maps do
if maps[i]:IsA("Folder") then -- checks if it is a model
table.insert(choices, maps[i]) -- ads the maps to the table
end
end
local picked = math.random(#maps) -- picks a random map and then sets the chosenmap value to the maps name
chosenmap.Value = choices[picked].Name
end
function loadMap()
local map = game.ServerStorage.Maps:FindFirstChild(chosenmap.Value):Clone() -- clones the map determined from the chosenmap value
map.Parent = currentmap
end
function deleteMap()
for i,v in pairs(currentmap:GetChildren()) do
if v:IsA("Folder") then -- checks to see if the things in the currentmap folder is a model
v:Destroy() -- destroys it if it is a model
end
end
end
coroutine.wrap(function()
while true do -- repeats forever and calls the functions
chooseMap()
loadMap()
wait(480)
deleteMap()
end
end)()
while true do
minutesvalue.Value = minutes
secondsvalue.Value = seconds
repeat
if secondsvalue.Value <= 0 then
minutesvalue.Value = minutesvalue.Value - 1
secondsvalue.Value = 59
else
secondsvalue.Value = secondsvalue.Value - 1
end
wait(1)
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
for _, v in pairs(game.Players:GetPlayers()) do
v.Character:WaitForChild("BeatObby").Value = false
local allplayers = players:GetPlayers()
for i, player in pairs(allplayers) do
wait(0.1)
player:LoadCharacter()
wait(0.1)
end
end
end
Still, the same problem happens. Please let me know if you know any ways to fix this issue. Thanks!
