What do I want to achieve? Round System with winning and working Intermission.
What is the issue? The attributes for clock dont reset to IntermissionTime.
Round Script:
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local LobbyTeam = game.Teams.Lobby
local TowerTeam = game.Teams.Tower
local AttackerTeam = game.Teams.Attacker
local Event = game.ReplicatedStorage.Events.StatusEvent
local Towers = game.ReplicatedStorage.Towers:GetChildren()
local TowerSpawnPos = Vector3.new(math.random(-14, 14), 166.5, math.random(120, 148))
local IntermissionTime = 10
local RoundTime = 90
local MinPlayers = 1
local function tpPlayers()
local players = Players:GetPlayers()
local pickedPlayer = players[math.random(#players)]
for i, player in players do
if player ~= pickedPlayer then
player.Team = AttackerTeam
player.Character.HumanoidRootPart.CFrame = game.Workspace.Attackers.AttackerPos.CFrame
else
player.Team = TowerTeam
player.Character.HumanoidRootPart.Position = TowerSpawnPos
end
end
end
local function tpPlayersBack()
local players = Players:GetPlayers()
for i, player in players do
player.Team = LobbyTeam
player.Character.HumanoidRootPart.Position = Vector3.new(0, 188, -27.5)
end
end
local function Countdown(duration)
for i = duration, 1, -1 do
workspace:SetAttribute("Clock", i)
task.wait(1)
end
end
local function Intermission()
workspace:SetAttribute("Status", "Intermission")
Countdown(IntermissionTime)
tpPlayers()
end
local function InGame()
workspace:SetAttribute("Status", "Game")
Countdown(RoundTime)
tpPlayersBack()
end
local function TowerWon()
workspace:SetAttribute("HasWon", true)
tpPlayersBack()
task.wait(1.5)
workspace:SetAttribute("HasWon", false)
workspace:SetAttribute("Status", "Intermission")
end
workspace.TowerWinPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
TowerWon()
end
end)
while true do
if #Players:GetPlayers() >= MinPlayers then
Intermission()
workspace:SetAttribute("Status", "Loading Tower...")
local randomTower = Towers[math.random(#Towers)]
local newTower = randomTower:Clone()
newTower.Parent = workspace.Tower
task.wait(1)
InGame()
newTower:Destroy()
else
warn("WAITING FOR PLAYERS...")
workspace:SetAttribute("Status", "Waiting for Players...")
task.wait(1)
end
end
Video on the problem:
The Intermission sould only be 10 seconds but its counting the InGame clock which is 90 seconds
Thank for your time! I have been trying to fix this for ages
I have this local script in the Gui to display the current game state
Script:
local RoundText = script.Parent
local Event = game.ReplicatedStorage.Events.StatusEvent
local function UpdateStatus()
local clockTime = workspace:GetAttribute("Clock")
local gameStatus = workspace:GetAttribute("Status")
local wonStatus = workspace:GetAttribute("HasWon")
if gameStatus == "Game" or gameStatus == "Intermission" then
RoundText.Text = gameStatus.." : ".. clockTime
else
RoundText.Text = gameStatus
end
if wonStatus == true then
RoundText.Text = "Tower has Won!"
end
end
workspace:GetAttributeChangedSignal("Clock"):Connect(UpdateStatus)
workspace:GetAttributeChangedSignal("Status"):Connect(UpdateStatus)
workspace:GetAttributeChangedSignal("HasWon"):Connect(UpdateStatus)
UpdateStatus()
local function TowerWon()
workspace:SetAttribute("HasWon", true)
tpPlayersBack()
task.wait(1.5)
for i = IntermissionTime, 1, -1 do
workspace:SetAttribute("Clock", i)
task.wait(1)
end
workspace:SetAttribute("HasWon", false)
workspace:SetAttribute("Status", "Intermission")
end
The Touched Event created a new thread and calls TowerWon().
But in the while loop, the InGame() function is still counting down.
Solution:
local function InGame()
workspace:SetAttribute("Status", "Game")
for i = duration, 1, -1 do
if workspace:GetAttribute("Status") ~= "Game"then
break
end
workspace:SetAttribute("Clock", i)
task.wait(1)
end
tpPlayersBack()
end
local function Countdown(duration)
for i = duration, 1, -1 do
if workspace:GetAttribute("HasWon") == true then
return
end
workspace:SetAttribute("Clock", i)
task.wait(1)
end
end
Maybe?
Sorry for strange formatting, wrote this on the reply box and it doesn’t let me use tab
while true do
if #Players:GetPlayers() >= MinPlayers then
Intermission()
workspace:SetAttribute("Status", "Loading Tower...")
local randomTower = Towers[math.random(#Towers)]
local newTower = randomTower:Clone()
newTower.Parent = workspace.Tower
task.wait(1) --I have to remove this wait LOLOL
InGame(RoundTime)
newTower:Destroy()
else
warn("WAITING FOR PLAYERS...")
workspace:SetAttribute("Status", "Waiting for Players...")
task.wait(1)
end
end