If statement won't run

Hello! I am making this training course for my game, and I am using this int value to get all the players while playing in the round, and in my main game runner I have it if somebody was playing the training round and died, that player would not have the playing the round value, but it won’t run for some reason. Here is the script.

--add player function that keeps track of current players
function addPlayer(player)
	local playing = Instance.new("BoolValue", player)
	playing.Value = false
	playing.Name = "Playing"
	
	--lots of other values that for the player that I deleted to be concise
	--remove character funciton that removes active players when they die or leave
	local function removeCharacter()
		if(player.Playing.Value == true) then
			--lots of other code for the main part of the game.....bla bla bla bla
	    end
		if player.TouchedStart.Value == true then
			game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value = game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value - 1
			player.TouchedStart.Value = false
	    end
	player.CharacterRemoving:Connect(removeCharacter)
end
game:GetService("Players").PlayerAdded:Connect(addPlayer)

this doesn’t make a whole lot of sense. Does anybody know what is wrong?

Hold on, I thought we are checking the players “Playing” BoolValue in here, also I don’t see the code that is handling the IntValue other than the .PlayerCount.Value what are you doing to add a player or remove one?

if so then why are we checking the TouchedStart value instead? Any explanation what is TouchedStart currently I don’t see it anywhere else in the code?

BTW, for creating an Instance like you did with:

	local playing = Instance.new("BoolValue", player)

it’s good practice to not have a second parent argument due to how Roblox events works in this tutorial:

also for code formatting, I recommend separating the functions like so just to make the addPlayer function less lengthy.

	--lots of other values that for the player that I deleted to be concise
	--remove character funciton that removes active players when they die or leave
	local function removeCharacter(player)
		if(player.Playing.Value == true) then
			--lots of other code for the main part of the game.....bla bla bla bla
	    end
		if player.TouchedStart.Value == true then
			game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value = game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value - 1
			player.TouchedStart.Value = false
	    end
end

function addPlayer(player)
	local playing = Instance.new("BoolValue", player)
	playing.Value = false
	playing.Name = "Playing"
	player.CharacterRemoving:Connect(removeCharacter(player))
end
game:GetService("Players").PlayerAdded:Connect(addPlayer)

Is that the whole script or just half of it?

My apologies, I did not explain that correctly. Let me start again.
I am trying to make a training course where if you step on a pad, it starts the training round.
Script for the pad:

local isReady = true
function onTouch(part)
	local character = part.Parent
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local player = game.Players:GetPlayerFromCharacter(character)
		player.TouchedStart.Value = true
		script.Parent.Parent.SpawnPlayerScript.Yes:Fire()
	end
	
end
script.Parent.Touched:Connect(onTouch)

and when it starts, this is the training round runner:

local head = script.Parent.Head
local goTo = script.Parent.GotoBrick
local goBack = script.Parent.GobackBrick
local StartingTimer = script.Parent.TimeStart.SurfaceGui.TextLabel
local RoundTimer1 = script.Parent.TIME1.SurfaceGui.TextLabel
local RoundTimer2 = script.Parent.TIME2.SurfaceGui.TextLabel
local RoundTimer3 = script.Parent.TIME3.SurfaceGui.TextLabel
local RoundTimer4 = script.Parent.TIME4.SurfaceGui.TextLabel
local somePlayers = false
math.randomseed(tick())
local roundInProgress = false
function Yes()
	if roundInProgress == false then
		roundInProgress = true
		for i = 15, 0, -1 do
			StartingTimer.Text = ("Training Round starts in..." .. i)
			wait(1)
		end
		StartingTimer.Text = ("Training Round in progress")
		local cacaClone = game.ServerStorage.TrainingAIs["Training Ax AI"]:Clone()
		local cacaClone2 = game.ServerStorage.TrainingAIs["Training Knife AI"]:Clone()
		local cacaClone3 = game.ServerStorage.TrainingAIs["Training Sword AI"]:Clone()
		cacaClone.Parent = workspace.AIsInTraining
		cacaClone2.Parent = workspace.AIsInTraining
		cacaClone3.Parent = workspace.AIsInTraining
		head.CFrame = goTo.CFrame
		for i, player in ipairs(game.Players:GetPlayers()) do
			if player.TouchedStart.Value == true then
				local whichSpawn = script.Parent.WhichSpawn:GetChildren()
				local teleLoc = math.random(1, #whichSpawn)
				local cheesy = whichSpawn[teleLoc]
				player.Character.HumanoidRootPart.CFrame = cheesy.CFrame
				local whichWeapon = game.ServerStorage.TrainingWeapons:GetChildren()
				local weaponNumber = math.random(1, #whichWeapon)
				local funky = whichWeapon[weaponNumber]:Clone()
				funky.Parent = player:WaitForChild("Backpack")
				script.Parent.PlayerCount.Value = script.Parent.PlayerCount.Value + 1
			end
		end
		for i = 90, 0, -1 do
			if script.Parent.PlayerCount.Value ~= 0 then
				RoundTimer1.Text = ("TIME:"..i)
				RoundTimer2.Text = ("TIME:"..i)
				RoundTimer3.Text = ("TIME:"..i)
				RoundTimer4.Text = ("TIME:"..i)
				wait(1)
			end
			if script.Parent.PlayerCount.Value == 0 then
				RoundTimer1.Text = ("Training Round Has Not Started")
				RoundTimer2.Text = ("Training Round Has Not Started")
				RoundTimer3.Text = ("Training Round Has Not Started")
				RoundTimer4.Text = ("Training Round Has Not Started")
				StartingTimer.Text = ("Training Round Has Not Started")
			end	
		end	
		RoundTimer1.Text = ("Training Round Has Not Started")
		RoundTimer2.Text = ("Training Round Has Not Started")
		RoundTimer3.Text = ("Training Round Has Not Started")
		RoundTimer4.Text = ("Training Round Has Not Started")
		StartingTimer.Text = ("Training Round Has Not Started")
		for i, player in ipairs(game.Players:GetPlayers()) do
			if player.TouchedStart.Value == true then
				player.TouchedStart.Value = false
				player:LoadCharacter()
				script.Parent.PlayerCount.Value = script.Parent.PlayerCount.Value - 1
			end
		end
		for i, AI in ipairs(game.Workspace.AIsInTraining:GetChildren()) do
			AI:Destroy()
		end
		head.CFrame = goBack.CFrame
		roundInProgress = false
	end
end
script.Yes.Event:Connect(Yes)

function No()
	for i, player in ipairs(game.Players:GetPlayers()) do
		if player.TouchedStart.Value == true then
			player:LoadCharacter()
			player.TouchedStart.Value = false
			
		end
	end
end
script.No.Event:Connect(No)

as you can see, I when they join the training round the int value is added by 1, and when they die or finish it is decreased by 1. Everything about that works, except for when players die. And I have this bit of code in my main game runner.

--add player function that keeps track of current players
function addPlayer(player)
	local playing = Instance.new("BoolValue", player)
	playing.Value = false
	playing.Name = "Playing"
	
	local hasHammer = Instance.new("BoolValue", player)
	hasHammer.Name = 'HasHammer'
	hasHammer.Value = false
	
	local refund = Instance.new("IntValue", player)
	refund.Name = 'Refund'
	refund.Value = 0
	
	local hasLauncher = Instance.new("BoolValue", player)
	hasLauncher.Name = 'HasLauncher'
	hasLauncher.Value = false
	
	local hasGunJeep = Instance.new("BoolValue", player)
	hasGunJeep.Name = 'HasGunJeep'
	hasGunJeep.Value = false
	
	local hasOrb = Instance.new("BoolValue", player)
	hasOrb.Name = 'HasOrb'
	hasOrb.Value = false
	
	local hasSneak = Instance.new("BoolValue", player)
	hasSneak.Name = 'HasSneak'
	hasSneak.Value = false
	
	local hasMeleeJeep = Instance.new("BoolValue", player)
	hasMeleeJeep.Name = 'HasMeleeJeep'
	hasMeleeJeep.Value = false
	
	local hasTankJeep = Instance.new("BoolValue", player)
	hasTankJeep.Name = 'HasTankJeep'
	hasTankJeep.Value = false
	
	local hasSpear = Instance.new("BoolValue", player)
	hasSpear.Name = 'HasSpear'
	hasSpear.Value = false
	
	local notkillable = Instance.new("BoolValue", player)
	notkillable.Name = 'Notkillable'
	notkillable.Value = false
	
	local hasNuke = Instance.new("BoolValue", player)
	hasNuke.Name = 'HasNuke'
	hasNuke.Value = false
	
	local hasCrossbow = Instance.new("BoolValue", player)
	hasCrossbow.Name = 'HasCrossbow'
	hasCrossbow.Value = false
	
	local hasStaff = Instance.new("BoolValue", player)
	hasStaff.Name = 'HasStaff'
	hasStaff.Value = false
	
	local hasMace = Instance.new("BoolValue", player)
	hasMace.Name = 'HasMace'
	hasMace.Value = false
	
	local hasMini = Instance.new("BoolValue", player)
	hasMini.Name = 'HasMini'
	hasMini.Value = false
	
	local giveOrb = Instance.new("BoolValue", player)
	giveOrb.Name = 'GiveOrb'
	giveOrb.Value = false
	
	local giveJeep = Instance.new("BoolValue", player)
	giveJeep.Name = 'GiveJeep'
	giveJeep.Value = false
	
	local nukePro = Instance.new("BoolValue", player)
	nukePro.Name = 'NukePro'
	nukePro.Value = false
	
	local VoteMap = Instance.new("BoolValue", player)
	VoteMap.Name = 'VoteMap'
	VoteMap.Value = false

	local touchedStart = Instance.new("BoolValue", player)
	touchedStart.Name = 'TouchedStart'
	touchedStart.Value = false
	
	wait(5)
		if player.leaderstats.POINTS.Value > 9 then
			player.leaderstats.LEVEL.Value = 2
		end
		if player.leaderstats.POINTS.Value > 19 then
			player.leaderstats.LEVEL.Value = 3
		end
		if player.leaderstats.POINTS.Value > 29 then
			player.leaderstats.LEVEL.Value = 4
		end
		if player.leaderstats.POINTS.Value > 39 then
			player.leaderstats.LEVEL.Value = 5
			player.HasCrossbow.Value = true
		end
		if player.leaderstats.POINTS.Value > 49 then
			player.leaderstats.LEVEL.Value = 6
		end
		if player.leaderstats.POINTS.Value > 59 then
			player.leaderstats.LEVEL.Value = 7
		end
		if player.leaderstats.POINTS.Value > 69 then
			player.leaderstats.LEVEL.Value = 8
		end
		if player.leaderstats.POINTS.Value > 79 then
			player.leaderstats.LEVEL.Value = 9
		end
		if player.leaderstats.POINTS.Value > 89 then
			player.leaderstats.LEVEL.Value = 10
		end
		if player.leaderstats.POINTS.Value > 99 then
			player.leaderstats.LEVEL.Value = 11
		end
		if player.leaderstats.POINTS.Value > 109 then
			player.leaderstats.LEVEL.Value = 12
			player.HasStaff.Value = true
		end
		if player.leaderstats.POINTS.Value > 119 then
			player.leaderstats.LEVEL.Value = 13
		end
		if player.leaderstats.POINTS.Value > 129 then
			player.leaderstats.LEVEL.Value = 14
		end
		if player.leaderstats.POINTS.Value > 139 then
			player.leaderstats.LEVEL.Value = 15
		end
		if player.leaderstats.POINTS.Value > 149 then
			player.leaderstats.LEVEL.Value = 16
		end
		if player.leaderstats.POINTS.Value > 159 then
			player.leaderstats.LEVEL.Value = 17
		end
		if player.leaderstats.POINTS.Value > 169 then
			player.leaderstats.LEVEL.Value = 18
		end
		if player.leaderstats.POINTS.Value > 179 then
			player.leaderstats.LEVEL.Value = 19
		end
		if player.leaderstats.POINTS.Value > 189 then
			player.leaderstats.LEVEL.Value = 20
			player.HasTankJeep.Value = true
		end
		if player.leaderstats.POINTS.Value > 199 then
			player.leaderstats.LEVEL.Value = 21
		end
		if player.leaderstats.POINTS.Value > 209 then
			player.leaderstats.LEVEL.Value = 22
		end
		if player.leaderstats.POINTS.Value > 219 then
			player.leaderstats.LEVEL.Value = 23
		end
		if player.leaderstats.POINTS.Value > 229 then
			player.leaderstats.LEVEL.Value = 24
		end
		if player.leaderstats.POINTS.Value > 239 then
			player.leaderstats.LEVEL.Value = 25
		end
	--remove character funciton that removes active players when they die or leave
	local function removeCharacter()
		if(player.Playing.Value == true) then
			if modeTeam == true then
				if player.Team == game.Teams["Red Team"] then
					aliveRedPlayers = aliveRedPlayers - 1
					alivePlayers = alivePlayers - 1
					player.Playing.Value = false
					player.leaderstats.CASH.Value = player.leaderstats.CASH.Value + 25
					Announce(player.Name .." Died")
				end
				if player.Team == game.Teams["Blue Team"] then
					aliveBluePlayers = aliveBluePlayers - 1
					alivePlayers = alivePlayers - 1
					player.Playing.Value = false
					player.leaderstats.CASH.Value = player.leaderstats.CASH.Value + 25
					Announce(player.Name .." Died")
				end
			end
			if modeNormal == true or modeNPW == true or modeAi == true or modeNWP == true then
				alivePlayers = alivePlayers - 1
				player.Playing.Value = false
				player.leaderstats.CASH.Value = player.leaderstats.CASH.Value + 25
				Announce(player.Name .." Died")
			end
		end
	end
	if player.TouchedStart.Value == true then
		game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value = game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value - 1
		player.TouchedStart.Value = false
	end	
	player.CharacterRemoving:Connect(removeCharacter)
end
game:GetService("Players").PlayerAdded:Connect(addPlayer)

don’t worry about all the extra instances and stuff, what I am trying to figure out is why this:

if player.TouchedStart.Value == true then
		game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value = game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value - 1
		player.TouchedStart.Value = false
	end

line of code won’t run when someone dies.
I am getting no errors what so ever.
and I can’t figure out why it won’t run.
Sorry my first post wasn’t very clear, I am kinda new at tthis.
oh by the way thanks for telling me about the instance thing, that was helpful

Yeah if you are getting no errors then you will have to interrogate the code through a process known as debugging. The easiest and simplest way to do it is through printing so try this, either something is wrong with the if the condition or the code below just isn’t changing for some reason.

print(player.TouchedStart.Value)
if player.TouchedStart.Value == true then
		game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value = game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value - 1
print(game.Workspace.SpawnBase.Barracks["Start Training"].PlayerCount.Value)
		player.TouchedStart.Value = false
	end

Edit: Also that’s a lot of if statements, I believe you can make it a lot more readable if you use tables, but IDK how for your scenario.

Also check this out:

Ok, yes I already put some break points in to see where the code stopped and the result was that when the game started, it paused at the if statement, so then I put some breakpoints on the inside of the if statement, and when the player died, nothing happened. I also looked at the value in the workspace while the player died and the value didn’t change