Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[EDITED AGAIN] What's wrong with this script?

This is what the output said when I created it. All it did so far was just make a hint message. It didn't have any text.

06:31:38.209 - Workspace.Script:85: attempt to compare number with boolean

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 --5 minutes
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 sfing 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 --This will loop the script every .5 seconds
local players = 0
local GameRun = false
local GameOver = false
local RegenTeams = false
function fixTeams()
local Blue = BlueTeam:Clone()
Blue.Parent = game.Teams
local Red = RedTeam:Clone()
Red.Parent = game.Teams 

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
end

function findwinner()
if GameOver 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
elseif player.TeamColor == RedTeam.TeamColor then
players = redplayers + 1
if redplayers == 0 then
print("Red team has lost")
M.Text = A6
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 then
fixteams()
RegenPlrs()
checkspectators()
findwinner()
end
end

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

1 answer

✓ Accepted answer

First of all: tab your code properly. It makes it much easier to read, especially on such long scripts.


The problem is this line, as the output says:

if not #A:GetPlayers() >= NumPlayers then

not is actually higher precedence than >=. That means the parenthesis that Lua infers look like this:

if (not #A:GetPlayers()) >= NumPlayers then

Since not <numbervalue> will always be true, you are comparing true to NumPlayers. (Your error: Comparing a number to a bool value (true))


Put parenthesis around the comparison, or just use < instead of not greater than or equal to:

if not ( #A:GetPlayers() >= NumPlayers ) then
-- or
if #A:GetPlayers() < NumPlayers then


You should really use better variable names. NumPlayers is not a good name for the number of players required to play, and A is bad name for the players service.

This discussion is preserved as it was. New answers, comments, and votes are closed.