Hello humans(hopefully)! This is my first time posting a scripting support topic, so any feedback is welcome.
Anyway, I was working on a round script for my game. Here it is.
local workspace = game.Workspace
local lobby = workspace.Lobby
local arena = workspace.Arena
local obstacles = arena.Obstacles
local projectiles = arena.Projectiles
local RoundEnd = script:WaitForChild("RoundEnd")
local Timer = game.ReplicatedStorage.UpdateGui.RoundDisplay
local teams = game.Teams
local blueTeam = teams.Blue
local redTeam = teams.Red
local lobbyTeam = teams.Lobby
local players = game.Players
local RoundTime = 600
local IntermissionTime = 30
local function timer(TotalTime)
for i = TotalTime, 0, -1 do
local minutes = tostring(math.floor(i/60))
local seconds = math.floor(i%60)
if seconds < 10 then
seconds = "0".. tostring(math.floor(i%60))
end
Timer.Value = minutes .. ":" .. seconds
wait(1)
end
RoundEnd:Fire()
end
local function TwoTeams()
local playersTable = players:GetPlayers()
local playerNumber = #playersTable
local redTeamNumber = math.floor((playerNumber + 1) / 2)
for i, v in pairs(playersTable) do
if i < (redTeamNumber + 1) then
v.Team = redTeam
print("teamed")
local spawnNumber = 1
if i > 4 then
spawnNumber = i - 4
end
local character = v.Character or v.CharacterAdded:Wait()
print("character variabled")
print("character found")
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
print("root found")
character.CableHook.Transparency = 1
character.CableHook.Cable.Enabled = false
character.CableHook.Weld.Part1 = nil
character.CableHook.Anchored = false
humanoidRootPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
humanoidRootPart.AssemblyAngularVelocity = Vector3.new(math.random(-50, 50), math.random(-50, 50), math.random(-50, 50))
humanoidRootPart.CFrame = obstacles.Red[spawnNumber].SpawnLocation.CFrame
end
end
end
end
wait(10)
while true do
TwoTeams()
timer(300)
--When a team has no players left
--Stop the timer
end
Anyway, the script works. I just need to know how I can stop the timer function. Is there like a function:Break() statement I can use? (I’m trying to stop the function from outside of the function)
I’ve tried browsing the Devforum and google for help, but I couldn’t find anything that works.
Thanks in advance!