hello,
so for my game, there are rounds… so i wanted to make a round system which plays infinitly and just plays every round automatically.
but for some reason, the first countdown in the script, ends at 1 and stays at 1 , for the rest of the game!
i don’t know why because i’m getting Zero errors and still it doesn’t work.
here is the script which implements the module:
local RoundModule = require(game.ReplicatedStorage.RoundModule)
local Raid = game.ReplicatedStorage:WaitForChild("ChangeRaid")
local Build = game.ReplicatedStorage:WaitForChild("ChangeBuild")
local Visible = game.ReplicatedStorage:WaitForChild("Visible")
game.Players.PlayerAdded:Connect(function(plr)
plr.Team = game.Teams.Lobby
end)
task.wait(5)
print("hello")
while true do
--RoundModule.Notify("Not Enough Players! :(")
--repeat wait() until RoundModule.Count() >= 2
RoundModule.StartTimer(20)--Visual representation
task.wait(20)--Functional Representation
RoundModule.LoadMap()
RoundModule.TeleportPlayers()
RoundModule.Notify("Activate The Cube!")
repeat wait() until RoundModule.CubeWasActivated
Visible:FireAllClients(true)
RoundModule.ChooseLeader()
RoundModule.SendRaider()
RoundModule.GrantTools()
RoundModule.ConnectEvents()
RoundModule.Waves = math.random(5,10)
while RoundModule.CurrentWave < RoundModule.Waves and not RoundModule.UserLeft and not RoundModule.CubeDied do
RoundModule.Notify("Build!")
Build:FireAllClients(true)
task.wait(1)
RoundModule.StartTimer(60)
task.wait(60)
Build:FireAllClients(false)
Raid:FireAllClients(true)
RoundModule.Notify("Raid!")
RoundModule.GrantWeapons()
task.wait(1)
RoundModule.StartTimer(20)
task.wait(20)
repeat wait() until RoundModule.EnemyCount() <= 0
RoundModule.CurrentWave += 1
RoundModule.Notify("Wave Ended!")
task.wait(1)
RoundModule.GrantResources()
end
RoundModule.Notify("Round Ended!")
RoundModule.Disconnect()
RoundModule.DestroyTools()
RoundModule.TeleportToLobby()
RoundModule.ResetTeams()
RoundModule.DeloadMap()
Visible:FireAllClients(false)
task.wait(5)
end
here is the module itself:
local module = {}
module.Waves = 15
module.CurrentWave = 0
module.EnemyResourceIncrement = 250 * module.CurrentWave
module.PlayerResourceIncrement = 1000
module.CubeWasActivated = false
module.UserLeft = false
module.CanBuild = false
module.CanSpawn = false
module.Amountofplrs = 0
module.CubeDied = false
local Connections = {}
module.StartTimer = function(Time)
local event = game.ReplicatedStorage.ChangeText
while Time > 0 do
event:FireAllClients("Time Left: "..Time)
Time -= 1
task.wait(1)
end
end
module.TeleportPlayers = function ()
local Players = game.Players:GetPlayers()
for i,v in pairs(Players) do
v.Character.PrimaryPart.Position = workspace:FindFirstChild("Map").SpawnBrick.Position + Vector3.new(0,2,0)
module.Amountofplrs += 1
end
module.UserLeft = false
module.CubeDied = false
end
module.LoadMap = function()
local Map = game.ServerStorage:WaitForChild("Map"):Clone()
Map.Parent = workspace
end
module.DeloadMap = function()
workspace:FindFirstChild("Map"):Destroy()
end
module.TeleportToLobby = function()
for i,v in pairs(game.Players:GetPlayers()) do
v.Character.PrimaryPart.Position = workspace.SpawnLocation.Position
end
end
module.GrantResources = function()
for i,v in pairs(game.Players:GetPlayers()) do
if v.Team == game.Teams.Lobby then continue end
if v.Team == game.Teams["The Raider"] then
local raid = v.Backpack:FindFirstChild("RaidShop")
if not raid then continue end
raid:SetAttribute("Resources",raid:GetAttribute("Resources") + module.EnemyResourceIncrement)
else
local shoup = v.Backpack:FindFirstChild("Shop")
if not shoup then continue end
shoup:SetAttribute("Resources",shoup:GetAttribute("Resources") + module.PlayerResourceIncrement)
end
end
end
module.ChooseLeader = function()
local Plrs = game.Players:GetPlayers()
local Num = math.random(1,#Plrs)
local Chosen = Plrs[Num]
Chosen.Team = game.Teams["The Raider"]
module.Amountofplrs -= 1
for i,v in pairs(Plrs) do
if v.Team == game.Teams["The Raider"] then continue end
v.Team = game.Teams["The Defenders"]
end
end
module.ConnectEvents = function()
table.insert(Connections,game.Players.PlayerRemoving:Connect(function(plr)
if plr.Team == game.Teams["The Raider"] then
module.CurrentWave = module.Waves
module.UserLeft = true
module.Notify("Raider Left!")
elseif plr.Team == game.Teams["The Defenders"] then
module.Amountofplrs -= 1
end
end))
for i,v in pairs(game.Players:GetPlayers()) do
table.insert(Connections,v.CharacterRemoving:Connect(function(char)
if v.Team == game.Teams["The Raider"] then
task.wait(2)
v.Character.PrimaryPart.Position = workspace:FindFirstChild("Map").RaiderSpawn.Position
elseif v.Team == game.Teams["The Defenders"] then
v.Team = game.Teams.Lobby
module.Amountofplrs -= 1
end
end))
end
end
module.GrantTools = function()
for i,v in pairs(game.Players:GetPlayers()) do
if v.Team == game.Teams["The Raider"] then
local Clone = game.ServerStorage.Tools:FindFirstChild("RaidShop"):Clone()
Clone.Parent = v.Backpack
elseif v.Team == game.Teams["The Defenders"] then
local clone = game.ServerStorage.Tools:FindFirstChild("Shop"):Clone()
clone.Parent = v.Backpack
end
end
end
module.DestroyTools = function()
for i,v in pairs(game.Players:GetPlayers()) do
local Tool = v.Backpack:FindFirstChild("RaidShop") or v.Backpack:FindFirstChild("Shop")
if not Tool then continue end
Tool:Destroy()
end
end
module.Disconnect = function()
for i,v in pairs(Connections) do
v:Disconnect()
end
end
module.ResetTeams = function()
for i,v in pairs(game.Players:GetPlayers()) do
v.Team = game.Teams.Lobby
end
end
module.Count = function()
local counter = 0
for i,v in pairs(game.Players:GetPlayers()) do
counter += 1
end
return counter
end
module.Notify = function(Text)
local event = game.ReplicatedStorage.ChangeText
event:FireAllClients(Text)
end
module.EnemyCount = function()
local Counter = 0
for i,v in pairs(workspace.Enemy:GetChildren()) do
Counter += 1
end
return Counter
end
module.SendRaider = function()
for i,v in pairs(game.Players:GetPlayers()) do
if v.Team ~= game.Teams["The Raider"] then return end
v.Character.PrimaryPart.Position = workspace:FindFirstChild("Map").RaiderSpawn.Position
end
end
module.GrantWeapons = function()
local Weapon = game.ServerStorage.Tools.CrossBow
for i,v in pairs(game.Players:GetPlayers()) do
if v.Team == game.Teams["The Raider"] then return end
Weapon:Clone().Parent = v.Backpack
end
end
return module
so i don’t know if you need this but:
and:
also i think it stops on the normal script at line task.wait but i’m not sure about that!
Thanks in advance!