Client script doesn't work in roblox

I have a client side script:

local folder = workspace:WaitForChild("QueueButtons")
local gamemode1
local inQueue = false
print("Loaded")
local function display(gamemode)
	print("function")
	script.Parent.Container:WaitForChild("Gamemode").Text = "Mode: ".. gamemode
	script.Parent.Container.Visible = true
end

script.Parent.Container.Exit.MouseButton1Click:Connect(function()
	print("exit")
	game:GetService("ReplicatedStorage"):WaitForChild("QueueRE"):FireServer("QUEUE",gamemode1)
	script.Parent.Container.Visible = false
	inQueue = false
end)
print("continue")
local Time =  script.Parent.Container.Timer 

local Start = tick()

function PlayTimer() 

	while inQueue == true do
		wait()

		local Difference = tick() - Start

		local Minutes = math.floor(Difference / 60)
		local Seconds = Difference - Minutes * 60
		Seconds = math.floor(Seconds)

		
		if string.len(Seconds) < 2 then Seconds = "0" .. Seconds end 
		if string.len(Minutes) < 2 then Minutes = "0" .. Minutes end

		local Format =  Minutes .. ":" .. Seconds

		Time.Text = Format
	end
	
end

print("continue 2")
game:GetService("ReplicatedStorage").QueueRE.OnClientEvent:Connect(function(typeA)
	print("Leacve")
	if typeA == "Leave" then
		game:GetService("ReplicatedStorage"):WaitForChild("QueueRE"):FireServer("QUEUE",gamemode1)
		script.Parent.Container.Visible = false
		inQueue = false
		script.Parent.Warning.Visible = true
		script.Parent.Warning.TextLabel.Text = "Something went wrong. You have been kick from the queue, please try again"
		task.wait(2)
		script.Parent.Warning.Visible = false
	end
end)
print("continue 3")
for i,v in pairs(folder:GetDescendants()) do
	print("descendant")
	if v:IsA("ProximityPrompt") then
		print("proximity")
		
		
		v.Triggered:Connect(function(player)
			print("Pressed")
			if inQueue == true then
				script.Parent.Warning.Visible = true
				script.Parent.Warning.TextLabel.Text = "Warning: you are already in a different queue"
				task.wait(2)
				script.Parent.Warning.Visible = false
				return 
			end
			display(v.Parent.Name)

		print("remove")
			game:GetService("ReplicatedStorage"):WaitForChild("QueueRE"):FireServer("IN QUEUE",v.Parent.Name)
			print("fired")
			gamemode1 = v.Parent.Name
			inQueue = true
			Start = tick()
			PlayTimer()

		end)
	end
end
print("end")

It works 100% of the time in studio but not in roblox, it sometimes works and sometimes doesn’t. In roblox, in prints all the continues and end but nothing else. Already tried publishing and there is no drafts/team create

I would say just putting task.wait(5) at the top would fix it. The problem is that it is loading the localscript before the game is loaded. It works in studio every time because you might load into studio quick enough but when you talk about servers and the delay it takes between clicking play, the game loading up, and it has already fired multiple things. This is further verified that everything prints fine. So that means to tell me the script itself is working but there is a problem between the game and the local script something is loading before something else.

The script works even the game is not loaded.wait the script till game is loaded then allow it to work.

repeat wait() until game:IsLoaded() end