[Beginner Scripter] Need Quick Fix please!

Hello, there I am making a auto team changer when the InGame Value = True.
There is also a countdown and I am trying to figure this out, I have tried to use this funtion but it doesn’t seem to work although when I print something it woks just fine.

local InGame = game.Workspace.MainSystem.InGame.Value
local status = game.workspace.MainSystem.GuiStat
local rTeam = game.Teams.Red
local bTeam = game.Teams.Blue

local players = game.Players:GetPlayers() --returns a table of all the players in-game

local function teamUp() --Funtion to Change Team

for i, v in pairs(players) do --loop through table

    if i % 2 == 0 then --if even number

       print("H") --Even

    else 
		print("M")	--blue team
	end
	end
	end


while true do
while InGame == false and status.Value > 0 do --Intermission since InGame is False
	wait(1)
	status.Value = status.Value - 1
	end
	if status.Value == 0 then
		InGame = true
		status.Value = 10
		
	end
	while InGame == true and status.Value > 0 do --Game in progress since InGame is True
	wait(1)
	status.Value = status.Value - 1 --Countdown
	if InGame == true then
		print("Hello")
		teamUp()
	end
		
	
	end
	end

If you have any questions please reply! Thanks I am excited to get my first game out there!

I’m not sure what the problem is other than “doesn’t seem to work” - are there any details more specific?

Is the value of InGame meant to always be true as that’s how it currently seems tor read?
(And do you realise that taking the value directly on line 1 means that it won’t update with the changes of the value object?)

1 Like

InGame Valué is true when the game is in progress and false when it’s not/intermission

Ok, I was saying the script wouldn’t take into account any changes to that value object.

Have you tried using the Debugger to step through the code to see which branches are taken and then working back to work out why it has taken the wrong branch?

Try this code. EDIT: REUSE THE CODE, HAD TO FIX SOMETHING

local InGame = game.Workspace.MainSystem.InGame
local status = game.workspace.MainSystem.GuiStat
local rTeam = game.Teams.Red
local bTeam = game.Teams.Blue

local players = game.Players:GetPlayers() --returns a table of all the players in-game

local function teamUp() --Funtion to Change Team

for i, v in pairs(players) do --loop through table

    if i % 2 == 0 then --if even number

       print("H") --Even

    else 
		print("M")	--blue team
	end
	end
	end


while true do
while InGame.Value == false and status.Value > 0 do --Intermission since InGame is False
	wait(1)
	status.Value = status.Value - 1
	end
	if status.Value == 0 then
		InGame.Value = true
		status.Value = 10
		
	end
	while InGame.Value == true and status.Value > 0 do --Game in progress since InGame is True
	wait(1)
	status.Value = status.Value - 1 --Countdown
	if InGame.Value == true then
		print("Hello")
		teamUp()
	end
		
	
	end
	end

I think the name status is a type of object and can’t be used as variable names. See these two Dev Hub Articles:

Try renaming status to something like gameStatus.

Setting a variable name to something that’s already exists will Just overwrite it, and the status class is deprecated.

oh ok. Sorry I couldn’t help :sad:

What did you change? I can’t see any changes within your script.

Value is only read-only with variables, so I changed it.

It doesn’t work, it prints hello it just doesn’t print “H” or “M”

I am not sure if this is the fix or related to, but it looks a little strange to me,

You have already said that only while InGame.Value == true, why do you need that extra if for?
and also, do you want the teams to change every second?

It’s a countdown and I have figured out that there is actually a way easier way to do it.

Great! so you solved it yourself?