Hello, I want to know how I could make a system that chooses a special round or something, first there would just be normal, but then it would multiply or add, I want to know how I could add or multiply the monster every 10 seconds, that then decreases to 2 over time, or until the round ends or when it reaches max limit.
Here is the script for the round, I was wondering if a while true do() loop would work but then it would keep repeating forever.
selectedEvent.Parent = workspace
selectedEvent:PivotTo(eventSpawn.CFrame)
Status.Value = "Subject Spawning"
task.wait(4.4) -- /// Waiting for Monster to be let out
-- /// Round
RoundMusic:Play()
for i = 120, 1, -1 do
Status.Value = TimerForm(i)
wait(1)
end
Status.Value = "Game has ended!"
selectedEvent:Destroy()
RoundMusic:Stop()
print("Game Ended")
task.wait(2)
currentMap:ClearAllChildren()
for _,Player in pairs(game.Players:GetPlayers()) do
Lobby.Parent = workspace
Player:LoadCharacter()
end
end
-- /// Restart
end
spawn(System)
I don’t know exactly what the code would look like, but I can help finding alternatives to while true.
For example, you have a Status.Value which is changed to “Game has Ended!” when it ends. So you could replace while true with while Status.Value ~= "Game Has Ended!".
To make the code run without interfering with your other code you could use task.spawn().
Example:
task.spawn(function()
while Status.Value ~= "Game has ended!" do
... -- Whatever code you would have to change those things
end
end)
for i = 120, 1, -1 do
... -- Your code continues as normal below this point.
Using task.spawn() makes the loop run on a different thread than the rest of the code, effectively making it run simultaneously. This means that those loops are independent from each other, and so both may start without waiting for the other to end.
I tried this but then it wouldn’t Pivot the event to the event spawn point, here is the entire script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Serverstorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")
-- /// Tables
local votes = {}
local voted = {}
-- /// Map Voting Functions
local function highestVote()
local map, highest = nil, 0
for i, v in pairs(votes) do
if v >= highest then
map = i
highest = v
end
end
return map
end
local function voteMaps()
local Status = ReplicatedStorage.RoundSystem:WaitForChild("Status")
votes = {}
voted = {}
local maps = {}
local mapsSelection = ReplicatedStorage.Maps:GetChildren()
repeat
local map = mapsSelection[math.random(1, #mapsSelection)]
if not table.find(maps, map.Name) then
table.insert(maps, map.Name)
votes[map.Name] = 0
end
until #maps == 2
ReplicatedStorage.RemoteEvents.Vote:FireAllClients(maps)
for i = 10, 0, -1 do
Status.Value = i
wait(1)
end
local selectedMap = ReplicatedStorage.Maps[highestVote()]:Clone()
selectedMap.Parent = workspace.CurrentMap
ReplicatedStorage.RemoteEvents.Vote:FireAllClients()
end
ReplicatedStorage.RemoteEvents.Vote.OnServerEvent:Connect(function(player, map)
if votes[map] and not table.find(voted, player.Name) then
table.insert(voted, player.Name)
votes[map] += 1
ReplicatedStorage.RemoteEvents.Update:FireAllClients(votes)
end
end)
local function TimerForm(s)
return string.format("%2i:%02i", s/60, s%60)
end
local function System()
-- /// Variables
local Status = ReplicatedStorage.RoundSystem:WaitForChild("Status")
local ServerStorage = game:GetService("ServerStorage")
local currentMap = workspace.CurrentMap
local Event = ServerStorage:FindFirstChild("Events"):GetChildren()
local Lobby = ServerStorage:FindFirstChild("Lobby"):Clone()
local Music = game.Workspace.Music
local IntermissionMusicFolder = Music.Intermission:GetChildren()
local IntermissionMusic = IntermissionMusicFolder[math.random(1, #IntermissionMusicFolder)]
local RoundMusicFolder = Music.RoundMusic:GetChildren()
local RoundMusic = RoundMusicFolder[math.random(1, #RoundMusicFolder)]
-- /// Game Loop
while task.wait() do
print("Intermission")
IntermissionMusic:Play()
for i = 20, 0, -1 do
Status.Value = i
wait(1)
end
Status.Value = "Vote for a Map!"
print("Map Voting")
-- /// Map Voting
voteMaps()
for _,Player in pairs(game.Players:GetPlayers()) do
workspace.Lobby:Destroy()
Player:LoadCharacter()
end
local selectedMap = ReplicatedStorage.Maps[highestVote()]:Clone()
IntermissionMusic:Stop()
-- /// Event Selection
Status.Value = "Selecting Subject"
local selectedEvent = Event[math.random(1, #Event)]:Clone()
local MultipliedEvent = Event[math.random(1, #Event)]:Clone()
task.wait(1)
Status.Value = "Selected Subject: " .. selectedEvent.Name
task.wait(2)
-- /// Spawning Event
local mapModel = selectedMap
local eventSpawn = nil
for _,v in pairs (mapModel:GetDescendants()) do
if (v.Name == "EventSpawn") then
print("Found Event Spawn Point")
eventSpawn = v
break
end
end
if (eventSpawn == nil) then
error("EventSpawn not found in map model")
end
print("Game Started")
-- /// Teleporting Event
selectedEvent.Parent = workspace
selectedEvent:PivotTo(eventSpawn.CFrame)
local function Multiply()
task.wait(5)
MultipliedEvent.Parent = workspace
MultipliedEvent:Pivot(eventSpawn.CFrame)
end
-- /// Round
RoundMusic:Play()
for i = 120, 0, -1 do
Status.Value = TimerForm(i)
wait(1)
task.spawn(function()
while Status.Value ~= "Game has ended!" do
Multiply()
end
end)
end
Status.Value = "Game has ended!"
selectedEvent:Destroy()
RoundMusic:Stop()
print("Game Ended")
task.wait(2)
currentMap:ClearAllChildren()
for _,Player in pairs(game.Players:GetPlayers()) do
Lobby.Parent = workspace
Player:LoadCharacter()
end
end
-- /// Restart
end
spawn(System)