Variables set to false without being set to false?

I’m making a script that will run a draft hall for my hockey league and for some reason this code will work with 1 person in the game but as soon as multiple people join it will break.

I’ve been print debugging for 2 hours and:


It appears to find a matching player but in the code below:

if WaitingForPick == true then
	print("Yup!")
	PickedPlayer = v
	WaitingForPick = false
else
	print("nope!")
end
break

This is the only part of the script that sets WaitingForPick to false, so how can WaitingForPick be false in the first place?
This is problematic because I can’t set the PickedPlayer value and my game errors
I’m just really confused and I have no idea how to fix this so if anyone can help me that would be nice
Here is the full code below: (Sorry it’s messy I was in a rush)

math.randomseed(tick())
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")

local TeamData = require(script.TeamData)
local Effects = require(script.Effects)
local Remotes = ReplicatedStorage.Remotes
local MessageRemote = Remotes.Message
local Teams = TeamData.GetTeams()
local Started = false
local PlayerTarget
local WaitingForCap = false
local PickingCap = false
local WaitingForPick = false
local PickedPlayerUsername
local PickedPlayer
local Admins = {
	["Complextic"] = true;
	["Iogician"] = true;
	["LimitedUHax"] = true;
	["Jabar_Lequatious"] = true;
	["KingBeIuga"] = true;
	["Desharious_Dillard"] = true;
	["LuckyEclipse"] = true;
}

local DraftList = {
	["Round 1"] = {
		"Toronto Maple Leafs";
		"St. Louis Blues";
		"Nashville Predators";
		"Vegas Golden Knights";
		"Vancouver Canucks";
		"Calgary Flames";
		"Columbus Blue Jackets";
		"Montreal Canadiens";
	};
	["Round 2"] = {
		"Montreal Canadiens";
		"Columbus Blue Jackets";
		"Calgary Flames";
		"Vancouver Canucks";
		"Vegas Golden Knights";
		"Nashville Predators";
		"St. Louis Blues";
		"Toronto Maple Leafs";
	};
	["Round 3"] = {
		"Toronto Maple Leafs";
		"St. Louis Blues";
		"Nashville Predators";
		"Vegas Golden Knights";
		"Vancouver Canucks";
		"Calgary Flames";
		"Columbus Blue Jackets";
		"Montreal Canadiens";
	};
	["Round 4"] = {
		"Montreal Canadiens";
		"Columbus Blue Jackets";
		"Calgary Flames";
		"Vancouver Canucks";
		"Vegas Golden Knights";
		"Nashville Predators";
		"St. Louis Blues";
		"Toronto Maple Leafs";
	};
	["Round 5"] = {
		"Toronto Maple Leafs";
		"St. Louis Blues";
		"Nashville Predators";
		"Vegas Golden Knights";
		"Vancouver Canucks";
		"Calgary Flames";
		"Columbus Blue Jackets";
		"Montreal Canadiens";
	};
	["Round 6"] = {
		"Montreal Canadiens";
		"Columbus Blue Jackets";
		"Calgary Flames";
		"Vancouver Canucks";
		"Vegas Golden Knights";
		"Nashville Predators";
		"St. Louis Blues";
		"Toronto Maple Leafs";
	};
	["Round 7"] = {
		"Toronto Maple Leafs";
		"St. Louis Blues";
		"Nashville Predators";
		"Vegas Golden Knights";
		"Vancouver Canucks";
		"Calgary Flames";
		"Columbus Blue Jackets";
		"Montreal Canadiens";
	};
	["Round 8"] = {
		"Montreal Canadiens";
		"Columbus Blue Jackets";
		"Calgary Flames";
		"Vancouver Canucks";
		"Vegas Golden Knights";
		"Nashville Predators";
		"St. Louis Blues";
		"Toronto Maple Leafs";
	};
	["Round 9"] = {
		"Vegas Golden Knights";
		"Toronto Maple Leafs";
		"Nashville Predators";
		"Detroit Red Wings";
		"Calgary Flames";
		"St. Louis Blues";
		"Columbus Blue Jackets";
		"Montreal Canadiens";
	};
}

function SendMessage(Target, Message, Length)
	if Target == "All" then
		MessageRemote:FireAllClients(Message, Length)
	else
		for i,v in pairs(Target) do
			MessageRemote:FireClient(v, Message, Length)
		end
	end
end

local TweeningInformation = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local Properties = {
	Volume = 0.1
}

local DefaultColor = Color3.fromRGB(0, 170, 255)
Effects.Color(DefaultColor)

function SecondsToClock(seconds)
  local seconds = tonumber(seconds)

  if seconds <= 0 then
    return "0:00";
  else
    local hours = string.format("%02.f", math.floor(seconds/3600));
    local mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
    local secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
    return mins..":"..secs
  end
end

local AvailableSongs = ServerStorage.Music:GetChildren()
function PickSound()
	ServerStorage.Values.PlayMusic.Value = false
	local CurrentMusic
	if ServerStorage.Values.CurrentSong.Value then
		CurrentMusic = ServerStorage.Values.CurrentSong.Value
		local Tween = TweenService:Create(CurrentMusic, TweeningInformation, Properties)
		Tween:Play()
		wait(1)
	end
	local Sound = ServerStorage.PickIsIn:Clone()
	Sound.Parent = workspace
	Sound:Play()
	Sound.Ended:Wait()
	Sound:Destroy()
	if CurrentMusic then
		Properties = {
			Volume = 1
		}
		local Tween = TweenService:Create(CurrentMusic, TweeningInformation, Properties)
		Tween:Play()
		
		wait(2)
		local TweeningInformation = TweenInfo.new(
			5,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		)
		Properties = {
			Volume = 0
		}
		local Tween = TweenService:Create(CurrentMusic, TweeningInformation, Properties)
		Tween:Play()
		wait(5)
		CurrentMusic:Destroy()
	end
	--Play new song
	local SelectedSong = AvailableSongs[math.random(1, #AvailableSongs)]
	local Audio = SelectedSong:Clone()
	CurrentMusic = Audio
	Audio.Parent = workspace
	ServerStorage.Values.CurrentSong.Value = Audio
	Audio:Play()
end

function CrowdTP(Player)
	local Selector = math.random(1, 2)
	if Selector == 1 then
		Player.Character:SetPrimaryPartCFrame(workspace.CS1.CFrame)
	elseif Selector == 2 then
		Player.Character:SetPrimaryPartCFrame(workspace.CS2.CFrame)
	end
end

function GetCaptain(Team)
	WaitingForCap = true
	print("Awaiting captain")
	repeat
		wait()
	until WaitingForCap == false
	print("Selected Captain: "..PickingCap.Name)
	local String = PickingCap.Name.." will pick for the "..Team
	SendMessage("All", String, 5)
	workspace.SCREENS.Middle.SurfaceGui.Clock.Text = ""
	repeat
		wait()
	until PickingCap.Character
	if PickingCap.Character.Humanoid.Sit == true then
		PickingCap.Character.Humanoid.Jump = true
	end
	wait(0.3)
	PickingCap.Character:SetPrimaryPartCFrame(workspace.StageTP.CFrame)
	return
end

function WalkoutAnimation(Player)
	print(33)
	repeat
		wait()
	until Player.Character
	Remotes.PlayerControls:FireClient(Player, false)
	local Character = Player.Character
	local Humanoid = Character.Humanoid
	if Humanoid.Sit == true then
		Humanoid.Jump = true
	end
	wait(0.3)
	Character:SetPrimaryPartCFrame(workspace.STAGESPAWN.CFrame)
	Remotes.Camera:FireAllClients(true, workspace.CameraPoints.ONE)
	wait(1)
	Humanoid:MoveTo(workspace.TWO.Position)
	Humanoid.MoveToFinished:Wait()
	wait(1)
	Remotes.Animate:FireClient(Player)
	wait(3)
	Remotes.Camera:FireAllClients(false, workspace.CameraPoints.TWO)
	Humanoid:MoveTo(workspace.THREE.Position)
	Humanoid.MoveToFinished:Wait()
	wait(1)
	Effects.Fire(true)
	Remotes.Camera:FireAllClients(false, workspace.CameraPoints.THREE)
	Humanoid:MoveTo(workspace.FOUR.Position)
	Humanoid.MoveToFinished:Wait()
	Humanoid:MoveTo(workspace.FIVE.Position)
	wait(1)
	Remotes.Camera:FireAllClients(false, workspace.CameraPoints.FOUR)
	Humanoid.MoveToFinished:Wait()
	Character:SetPrimaryPartCFrame(workspace.FIVE.CFrame)
	wait(2)
	Remotes.Camera:FireAllClients(false, workspace.CameraPoints.FIVE)
	wait(3)
	Remotes.Camera:FireAllClients(false, workspace.CameraPoints.SIX)
	wait(5)
	Remotes.Camera:FireAllClients(nil)
	Remotes.PlayerControls:FireClient(Player, true)
	Effects.Fire(false)
	wait(2)
	CrowdTP(Player)
	return
end

function GetPickedPlayer(Team)
	WaitingForPick = true
	print("Awaiting pick")
	local Seconds = 120
	local TimeString = SecondsToClock(Seconds)
	workspace.SCREENS.BottomLeft.SurfaceGui.Clock.Text = TimeString
	local Good = true
	repeat
		if Seconds <= 0 then
			Good = false
			break
		end
		wait(1)
		Seconds = Seconds - 1
		TimeString = SecondsToClock(Seconds)
		workspace.SCREENS.BottomLeft.SurfaceGui.Clock.Text = TimeString
	until WaitingForPick == false
	if Good == true then
		CrowdTP(PickingCap)
		PickingCap = nil
		workspace.SCREENS.Middle.SurfaceGui.Title.Text = Team
		workspace.SCREENS.Middle.SurfaceGui.Clock.Text = "THE PICK IS IN"
		PickSound()
		wait(1)
		workspace.SCREENS.Middle.SurfaceGui.Title.Text = "THE "..string.upper(Team).." SELECT: "
		print("PICKED!!!: "..PickedPlayer.Name)
		if PickedPlayer then
			print(1)
			workspace.SCREENS.Middle.SurfaceGui.Clock.Text = PickedPlayer.Name
			wait(5)
			WalkoutAnimation(PickedPlayer)
		else
			print(2)
			workspace.SCREENS.Middle.SurfaceGui.Clock.Text = PickedPlayerUsername
			wait(15)
		end
	else
		workspace.SCREENS.Middle.SurfaceGui.Title.Text = "PICK FORFEITTED"
	end
	PickedPlayer = nil
	PickedPlayerUsername = nil
	return
end

function PickDelay(Seconds)
	local TimeString = SecondsToClock(Seconds)
	workspace.SCREENS.BottomLeft.SurfaceGui.Clock.Text = TimeString
	local Good = true
	repeat
		wait(1)
		Seconds = Seconds - 1
		TimeString = SecondsToClock(Seconds)
		workspace.SCREENS.BottomLeft.SurfaceGui.Clock.Text = TimeString
	until Seconds <= 0
end

local CurrentRound = 1
local CurrentPick = 1
function DraftRunner()
	wait(2)
	local String = "Welcome to the first official draft of Hockey World League!"
	SendMessage("All", String, 5)
	wait(6)
	local String = "The draft will begin shortly."
	SendMessage("All", String, 5)
	wait(30)
	for i = 1, 9 do
		local IndexString = tostring(i)
		local IndexRound = "Round "..i
		local CurrentRound = DraftList[IndexRound]
		local String = "Now beginning "..IndexRound.."!"
		workspace.BigBoy.SurfaceGui.Round.Text = IndexRound
		SendMessage("All", String, 5)
		wait(6)
		for i,v in pairs(CurrentRound) do
			print("Pick: "..i.." for "..v.." in "..IndexRound)
			local TeamColor = TeamData.GetColor(v)
			workspace.BigBoy.SurfaceGui.Pick.Text = "Pick #"..CurrentPick
			workspace.SCREENS.Middle.SurfaceGui.Clock.Text = ""
			Effects.Color(TeamColor)
			local Logo = TeamData.GetLogo(v)
			workspace.SCREENS.TopLeft.SurfaceGui.ImageLabel.Image = Logo
			workspace.SCREENS.Middle.SurfaceGui.Title.Text = "THE "..string.upper(v).." ARE AWAITING A DRAFT SELECTOR"
			GetCaptain(v)
			workspace.SCREENS.Middle.SurfaceGui.Title.Text = "THE "..string.upper(v).." ARE ON THE CLOCK"
			GetPickedPlayer(v)
			workspace.SCREENS.Middle.SurfaceGui.Title.Text = ""
			workspace.SCREENS.Middle.SurfaceGui.Clock.Text = "INTERMISSION"
			PickDelay(20)
			CurrentPick = CurrentPick + 1
		end
		workspace.SCREENS.Middle.SurfaceGui.Title.Text = ""
		workspace.SCREENS.Middle.SurfaceGui.Clock.Text = "INTERMISSION"
		PickDelay(30)
		CurrentRound = CurrentRound + 1
	end
end

Players.PlayerAdded:Connect(function(Player)
	if Player.AccountAge <= 7 then
		Player:Kick("Account age too low.")
	end
	Player.Chatted:Connect(function(Message)
		local SimplifiedMessage = string.lower(Message)
		if Admins[Player.Name] then
			if SimplifiedMessage == "/e start" then
				if Started == false then
					Started = true
					DraftRunner()
				end
			elseif string.sub(SimplifiedMessage, 1, 10) == "/e picker " then
				local Length = string.len(SimplifiedMessage)
				for i,v in pairs(Players:GetChildren()) do
					local Match = true
					local PlayerName = string.lower(v.Name)
					local NameIndex = 1
					for i = 11, Length do
						local CurrentCharacter = string.sub(SimplifiedMessage, i, i)
						local NameCharacter = string.sub(PlayerName, NameIndex, NameIndex)
						NameIndex = NameIndex + 1
						if CurrentCharacter == NameCharacter then
							Match = true
						else
							Match = false
							break
						end
					end
					if Match == true then
						PlayerTarget = v
						local UserId = v.UserId
						local Username = v.Name
						--Bring picker to stage
						if WaitingForCap == true then
							WaitingForCap = false
							PickingCap = v
						end
					end
				end
			end
		end
		if Player == PickingCap or Admins[Player.Name] then
			if string.sub(SimplifiedMessage, 1, 8) == "/e pick " then
				local Length = string.len(SimplifiedMessage)
				for i,v in pairs(Players:GetChildren()) do
					print("Iterating players")
					local Match = true
					local PlayerName = string.lower(v.Name)
					local NameIndex = 1
					for i = 9, Length do
						print("iterating name")
						local CurrentCharacter = string.sub(SimplifiedMessage, i, i)
						local NameCharacter = string.sub(PlayerName, NameIndex, NameIndex)
						NameIndex = NameIndex + 1
						print(CurrentCharacter, NameCharacter)
						if CurrentCharacter == NameCharacter then
							Match = true
						else
							Match = false
							break
						end
					end
					if Match == true then
						print("match found")
						PlayerTarget = Player
						local UserId = Player.UserId
						local Username = Player.Name
						--Bring picker to stage
						print(WaitingForPick)
						if WaitingForPick == true then
							print("Yup!")
							PickedPlayer = v
							WaitingForPick = false
						else
							print("nope!")
						end
						break
					else
						print("no match found")
						if WaitingForPick == true then
							print("no match found 2")
							WaitingForPick = false
							PickedPlayerUsername = string.sub(Message, 9, string.len(Message))
						end
					end
				end
			end
		end
	end)
end)

spawn(function()
	while true do
		wait(1)
		print(WaitingForPick)
	end
end)

so how can WaitingForPick be false in the first place?

At the top of your code in the variables, WaitingForPick is set to false.

In the function GetPickedPlayer(), this print is never printed:

print("Awaiting pick")

Which means the code didn’t get past this point, and seeing as how the only other code above it is:

WaitingForPick = true

Then my guess is this function is never getting called in the first place. I suspect the problem lies in your DraftRunner() function.

Awaiting Pick actualy prints above that so that’s not that problem, I also had a while true do loop printing the variable and I couldn’t see anything wrong.

1 Like

Try to set the WaitingForPick to true, and then change it to false.

What confuses me a lot is the whole /e picker command runs the exact same way as the /e pick command, I literally copy pasted them and just changed the variables, so I’m really not sure why this isnt working