Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

After this script does all the functions, it breaks?...

Asked by
Irvene 5
10 years ago

Whenever I try this out, I make it so if 2 players joined the game, then GameRun = true, but the issue with this is that it teams players, on red, and blue, resets them, but it doesn't restart when the game's over! It's frustrating, and confusing I'd like some help please, I worked hard on this...

Here's the script;

local BlueTeam = game.Teams["BlueTeam"]:Clone()
local RedTeam = game.Teams["RedTeam"]:Clone()
local NumPlayers = 2

repeat wait(0)until game:FindFirstChild("Teams")
local GameTime = 250
local A = game:service('Players')
local A1 = "This service is unavailable, please wait until 1 more player joins..."
local A2 = "Welcome to the official meadows swordfighting game"
local A4 = "5"
local A3 = "The amount of players is successful, and the game will be starting in" .. A4 .. "Seconds.."
local A5 = "Teaming players..."
local A6 = "Blue team has won"
local A7 = "Red team has won"
local redplayers = 0
local blueplayers = 0
local M = Instance.new("Message",game.Workspace)
local H = Instance.new("Hint",game.Workspace)
local TimeForLoop = .5
local players = 0
local GameRun = false
local GameOver = false
local RegenTeams = false

function teams()
team1 = "Bright red"
team2 = "Bright blue" 
wait(.3)
M.Text = A5
wait(.3)
M:remove()
wait(.1)
H:remove()
team1 = "Bright red"
team2 = "Bright blue" 
M.Text = A5

t1=0
t2=0
for i,v in pairs (game.Players:GetChildren()) do
if t1 < t2 then
t1 = t1+1
v.TeamColor = BrickColor.new(team1)
else
t2 = t2+1
v.TeamColor = BrickColor.new(team2)
wait(5)
end
end
end

function checkSpectators()
spectators = 0
for _, player in pairs(game:service('Players'):GetChildren()) do
if player.TeamColor == game.Teams.Spectators.TeamColor then
spectators = spectators + 1 end
if(spectators >= NumPlayers) then
game.Teams.BlueTeam:remove()
game.Teams.RedTeam:remove()
end

wait(3)
end
end


function findwinner()
if GameOver == false then
for _, player in pairs(game.Players:GetPlayers()) do
if player.TeamColor == BlueTeam.TeamColor then
players = blueplayers + 1
wait(5)
if blueplayers == 0 then
print("Blue team has lost")
M.Text = A7
GameOver = true
elseif player.TeamColor == RedTeam.TeamColor then
players = redplayers + 1
if redplayers == 0 then
print("Red team has lost")
M.Text = A6
GameOver = true
end
end
end
end
end
end

function RegenPlrs()
for i,v in pairs(game.Players:GetPlayers())do
if v and v.Character then
v.Character:BreakJoints()
end
end
end

function StartGame()
if GameRun == true then
teams()
RegenPlrs()
checkspectators()
findwinner()
end
end

coroutine.resume(coroutine.create(function()
while wait(TimeForLoop)do
if not ( #A:GetPlayers() >= NumPlayers ) then
M.Text = A1
else
GameRun = true
StartGame()
M.Text = ""
wait(1)
M.Text = A2
wait(5)
M.Text = A3
for z = 5, 0, -1 do
M.Text = ""..z
wait(1)

for i = GameTime, 0, -1 do
H.Text = "Time left: "..i
wait(1)
end
wait(2)
M.Text = "Times up!"
wait(2)
M.Text = "Starting new round..."
wait(2.5)
end
end
end
end))


1 answer

Log in to vote
0
Answered by
DevChris 235 Moderation Voter
10 years ago

Could you post the output in script format, please?

Also, things like this aren't neccessary unless they have spaces, numbers at the start or any unusual characters:

local BlueTeam = game.Teams["BlueTeam"]:Clone()
local RedTeam = game.Teams["RedTeam"]:Clone()

Do this:

local BlueTeam = game.Teams.BlueTeam:Clone()
local RedTeam = game.Teams.RedTeam:Clone()
Ad

Answer this question