local maps = game.Lighting:FindFirstChild("Maps")
local rSTORage = game:GetService("ReplicatedStorage")
local value = rSTORage:WaitForChild("Time")
function chooseRandom(tab)
local n = math.random(1,#tab)
local obj = tab[n]
return obj
end
while true do
task.wait(0.1)
local map = chooseRandom(maps:GetChildren()):Clone()
map.Parent = workspace
game.ReplicatedStorage.MapMessage:FireAllClients(map.Name)
script.Parent["button.wav"]:Play()
task.wait(value.Value)
map:Destroy()
end
Timer:
local replicatedStorage = game:GetService("ReplicatedStorage")
local timerValue = replicatedStorage:WaitForChild("Time")
local function startTimer()
while true do
wait(1)
timerValue.Value = timerValue.Value - 1
if timerValue.Value <= 0 then
timerValue.Value = 300
end
end
end
startTimer()
Hello, I have a problem with these 2 scripts. When the timer ends instead of cloning 1 map it clones 2: 1 like before the timer ends (3s before) and 1 when the timer really ends (and deletes the one cloned before the timer ended.) and I don’t know how to fix it. I appreciate any help. Thanks.
The round script is in workspace and the timer script is in serverscriptservice
I feel like this could be done by using BindableEvents
Here is a modified version of your script which needs a BindableEvent in workspace called “LoadMap” and another one called “DestroyMap”
Round
local maps = game.Lighting:FindFirstChild("Maps")
local rSTORage = game:GetService("ReplicatedStorage")
local value = rSTORage:WaitForChild("Time")
function chooseRandom(tab)
local n = math.random(1,#tab)
local obj = tab[n]
return obj
end
game.Workspace.LoadMap.Event:Connect(function()
local map = chooseRandom(maps:GetChildren()):Clone()
map.Parent = workspace
game.ReplicatedStorage.MapMessage:FireAllClients(map.Name)
script.Parent["button.wav"]:Play()
local destroy
destroy = game.Workspace.DestroyMap.Event:Connect(function()
map:Destroy()
destroy:Disconnect()
end)
end)
Timer
local replicatedStorage = game:GetService("ReplicatedStorage")
local timerValue = replicatedStorage:WaitForChild("Time")
local function startTimer()
while true do
wait(1)
timerValue.Value = timerValue.Value - 1
if timerValue.Value <= 0 then
timerValue.Value = 300
game.Workspace.DestroyMap:Fire()
wait(0.01)
game.Workspace.LoadMap:Fire()
end
end
end
startTimer()
When the timer ends, it will be set back to 300 and first it will destroy the current map, then it will load another one. I am unsure if this is what you wanted.
If it does not work, or if you’d like to use another way, please inform me.