Remote event firing twice after firing once the first time, need help

I have been trying to figure this out alone for 4 hours straight, its a major flaw in my game and I have had no luck at all.
So pretty much you can go into a ui click a button that will fire a remote event to start a match and then after its over you want to fire it again and it does it twice, i have taken every precaution to even disconnect the events but still no luck.

Here is where the event is taking place… (local)


local connection
connection = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnClientEvent:Connect(function(player)
	
	if LocalPlayer.ValuesGame.Practice.Value == false then
		if LocalPlayer.ValuesGame.Game.Value == false then
		ClickUI:Play()
		BlurTween()
		MainFrame.Visible = false
		task.wait(5)
			ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData:FireServer(player)

		--=========== CAMERAS
			
			local connection2
			connection2 = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData.OnClientEvent:Connect(function(Teamname)
				
			
	
			local GameCameras = Workspace:WaitForChild("Tycoon").Tycoons:WaitForChild(Teamname).Essentials.GamedayCameras
			Camera.CameraType = Enum.CameraType.Scriptable

			local CamTween1 = TweenService:Create(Camera,TweenInfo.new(
				3,
				Enum.EasingStyle.Quad,
				Enum.EasingDirection.In),
				{
					CFrame = GameCameras.Camera1.CFrame
				})

			CamTween1:Play()
			StadiumAmbience:Play()
			CamTween1.Completed:Wait()

			TutorialText.Text = ""
			TutorialText.Visible = true


			UnBlurTween()
			task.wait(3)

			PlayerGui.Player.Skip.Visible = true

			PlayerGui.Player.Skip.MouseButton1Click:Connect(function(plr)
				PlayerGui.Player.GameUI.Visible = true
				PlayerGui.Player:WaitForChild("Skip").Visible = false
				PlayerGui.Player.Skip.Value.Value = true
				ClickUI:Play()
				typewrite(TutorialText, "")
				TutorialText.Text = ""
				TutorialText.Visible = false
				CameraNormal()
				ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer(plr)
				SoundService.Gameday:WaitForChild("Spotlights"):Stop()
			end)

			--// Game Commentary Start
			SoundService.Gameday:WaitForChild("Spotlights"):Play()
			task.wait(1)

			typewrite(TutorialText, "IT IS TIME!!")

			PlayerGui.Player.Skip.Visible = false


			if PlayerGui.Player.Skip.Value.Value == true then
			else
				local CamTween2 = TweenService:Create(Camera,TweenInfo.new(
					3,
					Enum.EasingStyle.Quad,
					Enum.EasingDirection.In),
					{
						CFrame = GameCameras.Camera2.CFrame
					})

				CamTween2:Play()
				task.wait(1)
				typewrite(TutorialText, "Today the "..LocalPlayer.ValuesGame.TeamName.Value.." will be facing the ".. randomteam.." this will be a very good game!")
				task.wait(1)
				local CamTween3 = TweenService:Create(Camera,TweenInfo.new(
					5,
					Enum.EasingStyle.Quad,
					Enum.EasingDirection.In),
					{
						CFrame = GameCameras.Camera3.CFrame
					})

				CamTween3:Play()
				typewrite(TutorialText, "We welcome you to the Week ".. LocalPlayer.ValuesGame.Team.Week.Value.. " matchup and we bring you now down to the coin toss.")

				TutorialText.Visible = false

				task.wait(1)
				local CoinFlip = PlayerGui.Player.CoinFlip
				CoinFlip.Visible = true

				CoinFlip.Heads.MouseButton1Click:Connect(function(plr)
					CoinFlip.Visible = false
					ClickUI:Play()
					local chance = math.random(1,100)
					if chance > 50 then
						CoinFlip.Flip.Value = true

					
						CrowdCheer:Play()

						TutorialText.Visible = true
						typewrite(TutorialText, "It seems the ".. LocalPlayer.ValuesGame.TeamName.Value.." won the coin toss!")
					elseif chance <= 50 then
						CoinFlip.Flip.Value = true
						CrowdAw:Play()
					

						TutorialText.Visible = true
						typewrite(TutorialText, "The ".. LocalPlayer.ValuesGame.TeamName.Value.." lost the coin toss. ")

					end
				end)

				CoinFlip.Tails.MouseButton1Click:Connect(function(plr)
					CoinFlip.Visible = false
					ClickUI:Play()
					local chance = math.random(1,100)
					if chance > 50 then
						CoinFlip.Flip.Value = true
					
						CrowdCheer:Play()

						TutorialText.Visible = true
						typewrite(TutorialText, "It seems the ".. LocalPlayer.ValuesGame.TeamName.Value.." won the coin toss!")
					elseif chance <= 50 then
						CoinFlip.Flip.Value = true
					
						CrowdAw:Play()

						TutorialText.Visible = true
						typewrite(TutorialText, "The ".. LocalPlayer.ValuesGame.TeamName.Value.." lost the coin toss. ")
					end
				end)

				CoinFlip.Flip.Changed:Connect(function(plr)
					task.wait(3)
					local CamTween4 = TweenService:Create(Camera,TweenInfo.new(
						3,
						Enum.EasingStyle.Quad,
						Enum.EasingDirection.In),
						{
							CFrame = GameCameras.Camera4.CFrame
						})

					CamTween4:Play()
					typewrite(TutorialText, "The game is underway here at " .. LocalPlayer.ValuesGame.TeamName.Value.. " field!")

					task.wait(3)

					TutorialText.Visible = false
					CameraNormal()

					if PlayerGui.Player.Skip.Value.Value == true then
					else
						ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer(plr)
						PlayerGui.Player.GameUI.Visible = true
						PlayerGui.Player.GameUI.TimeFrame.Quarter.Value += 1
						end
					end)
				end
			connection2:Disconnect()
			end)
		end
	end
	connection:Disconnect()
end)

Here is where the button is firing this event

local buttonClicked = false
	actualstartgame = MainFrame.Gamestart.Yes.MouseButton1Click:Connect(function(player, ...)
		if not buttonClicked then
			buttonClicked = true
			MainFrame.Gamestart.Visible = false
			MainFrame.Visible = false
			ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote:FireServer(player)
		end
		
	end)

Here is where the event is going to the server (this fires back to the client taken place in the 1st code linked)

local connection
connection = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnServerEvent:Connect(function(player)
	local remoteEvent = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote
-- Optionally, you can fire the event back to the client
		remoteEvent:FireClient(player)
		connection:Disconnect()
end)

anybody knows whats going on, please help and thank you if you do I very very much appreciate it.

2 Likes

Let me know if this fixes your problem and if so i think i can explain the issue

--Client Script
local connection -- Ensure one persistent connection
local activeConnections = {}
local buttonClicked = false

-- Cleanup function
local function cleanupConnections()
    for _, conn in ipairs(activeConnections) do
        if conn.Connected then
            conn:Disconnect()
        end
    end
    activeConnections = {}
end

-- Main button logic
actualstartgame = MainFrame.Gamestart.Yes.MouseButton1Click:Connect(function(player, ...)
    if not buttonClicked then
        buttonClicked = true
        MainFrame.Gamestart.Visible = false
        MainFrame.Visible = false
        cleanupConnections() -- Clean up old connections before starting new ones

        connection = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnClientEvent:Connect(function(player)
            -- Event logic here
        end)

        table.insert(activeConnections, connection)
    end
end)
2 Likes

testing it right now… i added the fireserver event above the cleanupConnections() to send the remote to the server to send it back to the client to start the first connection, ill get back to you in one second.

2 Likes

hi
I think you have to take the skip button connection out of your onClientEvent connection because you create one for each event.

PlayerGui.Player.Skip.MouseButton1Click:Connect(function(plr)
	PlayerGui.Player.GameUI.Visible = true
	PlayerGui.Player:WaitForChild("Skip").Visible = false
	PlayerGui.Player.Skip.Value.Value = true
	ClickUI:Play()
	typewrite(TutorialText, "")
	TutorialText.Text = ""
	TutorialText.Visible = false
	CameraNormal()
	ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer(plr)
	SoundService.Gameday:WaitForChild("Spotlights"):Stop()
end)

local connection
connection = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnClientEvent:Connect(function(player)

	if LocalPlayer.ValuesGame.Practice.Value == false then
		if LocalPlayer.ValuesGame.Game.Value == false then
			ClickUI:Play()
			BlurTween()
			MainFrame.Visible = false
			task.wait(5)
			ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData:FireServer(player)

			--=========== CAMERAS

			local connection2
			connection2 = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData.OnClientEvent:Connect(function(Teamname)



				local GameCameras = Workspace:WaitForChild("Tycoon").Tycoons:WaitForChild(Teamname).Essentials.GamedayCameras
				Camera.CameraType = Enum.CameraType.Scriptable

				local CamTween1 = TweenService:Create(Camera,TweenInfo.new(
					3,
					Enum.EasingStyle.Quad,
					Enum.EasingDirection.In),
					{
						CFrame = GameCameras.Camera1.CFrame
					})

				CamTween1:Play()
				StadiumAmbience:Play()
				CamTween1.Completed:Wait()

				TutorialText.Text = ""
				TutorialText.Visible = true


				UnBlurTween()
				task.wait(3)

				PlayerGui.Player.Skip.Visible = true

				

				--// Game Commentary Start
				SoundService.Gameday:WaitForChild("Spotlights"):Play()
				task.wait(1)

				typewrite(TutorialText, "IT IS TIME!!")

				PlayerGui.Player.Skip.Visible = false


				if PlayerGui.Player.Skip.Value.Value == true then
				else
					local CamTween2 = TweenService:Create(Camera,TweenInfo.new(
						3,
						Enum.EasingStyle.Quad,
						Enum.EasingDirection.In),
						{
							CFrame = GameCameras.Camera2.CFrame
						})

					CamTween2:Play()
					task.wait(1)
					typewrite(TutorialText, "Today the "..LocalPlayer.ValuesGame.TeamName.Value.." will be facing the ".. randomteam.." this will be a very good game!")
					task.wait(1)
					local CamTween3 = TweenService:Create(Camera,TweenInfo.new(
						5,
						Enum.EasingStyle.Quad,
						Enum.EasingDirection.In),
						{
							CFrame = GameCameras.Camera3.CFrame
						})

					CamTween3:Play()
					typewrite(TutorialText, "We welcome you to the Week ".. LocalPlayer.ValuesGame.Team.Week.Value.. " matchup and we bring you now down to the coin toss.")

					TutorialText.Visible = false

					task.wait(1)
					local CoinFlip = PlayerGui.Player.CoinFlip
					CoinFlip.Visible = true

					CoinFlip.Heads.MouseButton1Click:Connect(function(plr)
						CoinFlip.Visible = false
						ClickUI:Play()
						local chance = math.random(1,100)
						if chance > 50 then
							CoinFlip.Flip.Value = true


							CrowdCheer:Play()

							TutorialText.Visible = true
							typewrite(TutorialText, "It seems the ".. LocalPlayer.ValuesGame.TeamName.Value.." won the coin toss!")
						elseif chance <= 50 then
							CoinFlip.Flip.Value = true
							CrowdAw:Play()


							TutorialText.Visible = true
							typewrite(TutorialText, "The ".. LocalPlayer.ValuesGame.TeamName.Value.." lost the coin toss. ")

						end
					end)

					CoinFlip.Tails.MouseButton1Click:Connect(function(plr)
						CoinFlip.Visible = false
						ClickUI:Play()
						local chance = math.random(1,100)
						if chance > 50 then
							CoinFlip.Flip.Value = true

							CrowdCheer:Play()

							TutorialText.Visible = true
							typewrite(TutorialText, "It seems the ".. LocalPlayer.ValuesGame.TeamName.Value.." won the coin toss!")
						elseif chance <= 50 then
							CoinFlip.Flip.Value = true

							CrowdAw:Play()

							TutorialText.Visible = true
							typewrite(TutorialText, "The ".. LocalPlayer.ValuesGame.TeamName.Value.." lost the coin toss. ")
						end
					end)

					CoinFlip.Flip.Changed:Connect(function(plr)
						task.wait(3)
						local CamTween4 = TweenService:Create(Camera,TweenInfo.new(
							3,
							Enum.EasingStyle.Quad,
							Enum.EasingDirection.In),
							{
								CFrame = GameCameras.Camera4.CFrame
							})

						CamTween4:Play()
						typewrite(TutorialText, "The game is underway here at " .. LocalPlayer.ValuesGame.TeamName.Value.. " field!")

						task.wait(3)

						TutorialText.Visible = false
						CameraNormal()

						if PlayerGui.Player.Skip.Value.Value == true then
						else
							ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer(plr)
							PlayerGui.Player.GameUI.Visible = true
							PlayerGui.Player.GameUI.TimeFrame.Quarter.Value += 1
						end
					end)
				end
				connection2:Disconnect()
			end)
		end
	end
	connection:Disconnect()
end)
1 Like
local connection -- Ensure one persistent connection
	local activeConnections = {}
	local buttonClicked = false

	-- Cleanup function
	local function cleanupConnections()
		for _, conn in ipairs(activeConnections) do
			if conn.Connected then
				conn:Disconnect()
			end
		end
		activeConnections = {}
	end
	
	PlayerGui.Player.Skip.MouseButton1Click:Connect(function(plr)
		PlayerGui.Player.GameUI.Visible = true
		PlayerGui.Player:WaitForChild("Skip").Visible = false
		PlayerGui.Player.Skip.Value.Value = true
		ClickUI:Play()
		typewrite(TutorialText, "")
		TutorialText.Text = ""
		TutorialText.Visible = false
		CameraNormal()
		ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer(plr)
		SoundService.Gameday:WaitForChild("Spotlights"):Stop()
	end)

	-- Main button logic
	actualstartgame = MainFrame.Gamestart.Yes.MouseButton1Click:Connect(function(player, ...)
		if not buttonClicked then
			buttonClicked = true
			MainFrame.Gamestart.Visible = false
			MainFrame.Visible = false
			ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote:FireServer(player)
			cleanupConnections() -- Clean up old connections before starting new ones
			connection = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnClientEvent:Connect(function(player)
				if LocalPlayer.ValuesGame.Practice.Value == false then
					if LocalPlayer.ValuesGame.Game.Value == false then
						ClickUI:Play()
						BlurTween()
						MainFrame.Visible = false
						task.wait(5)
						ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData:FireServer(player)

						--=========== CAMERAS

						local connection2
						connection2 = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData.OnClientEvent:Connect(function(Teamname)



							local GameCameras = Workspace:WaitForChild("Tycoon").Tycoons:WaitForChild(Teamname).Essentials.GamedayCameras
							Camera.CameraType = Enum.CameraType.Scriptable

							local CamTween1 = TweenService:Create(Camera,TweenInfo.new(
								3,
								Enum.EasingStyle.Quad,
								Enum.EasingDirection.In),
								{
									CFrame = GameCameras.Camera1.CFrame
								})

							CamTween1:Play()
							StadiumAmbience:Play()
							CamTween1.Completed:Wait()

							TutorialText.Text = ""
							TutorialText.Visible = true


							UnBlurTween()
							task.wait(3)

							PlayerGui.Player.Skip.Visible = true


							--// Game Commentary Start
							SoundService.Gameday:WaitForChild("Spotlights"):Play()
							task.wait(1)

							typewrite(TutorialText, "IT IS TIME!!")

							PlayerGui.Player.Skip.Visible = false


							if PlayerGui.Player.Skip.Value.Value == true then
							else
								local CamTween2 = TweenService:Create(Camera,TweenInfo.new(
									3,
									Enum.EasingStyle.Quad,
									Enum.EasingDirection.In),
									{
										CFrame = GameCameras.Camera2.CFrame
									})

								CamTween2:Play()
								task.wait(1)
								typewrite(TutorialText, "Today the "..LocalPlayer.ValuesGame.TeamName.Value.." will be facing the ".. randomteam.." this will be a very good game!")
								task.wait(1)
								local CamTween3 = TweenService:Create(Camera,TweenInfo.new(
									5,
									Enum.EasingStyle.Quad,
									Enum.EasingDirection.In),
									{
										CFrame = GameCameras.Camera3.CFrame
									})

								CamTween3:Play()
								typewrite(TutorialText, "We welcome you to the Week ".. LocalPlayer.ValuesGame.Team.Week.Value.. " matchup and we bring you now down to the coin toss.")

								TutorialText.Visible = false

								task.wait(1)
								local CoinFlip = PlayerGui.Player.CoinFlip
								CoinFlip.Visible = true

								CoinFlip.Heads.MouseButton1Click:Connect(function(plr)
									CoinFlip.Visible = false
									ClickUI:Play()
									local chance = math.random(1,100)
									if chance > 50 then
										CoinFlip.Flip.Value = true


										CrowdCheer:Play()

										TutorialText.Visible = true
										typewrite(TutorialText, "It seems the ".. LocalPlayer.ValuesGame.TeamName.Value.." won the coin toss!")
									elseif chance <= 50 then
										CoinFlip.Flip.Value = true
										CrowdAw:Play()


										TutorialText.Visible = true
										typewrite(TutorialText, "The ".. LocalPlayer.ValuesGame.TeamName.Value.." lost the coin toss. ")

									end
								end)

								CoinFlip.Tails.MouseButton1Click:Connect(function(plr)
									CoinFlip.Visible = false
									ClickUI:Play()
									local chance = math.random(1,100)
									if chance > 50 then
										CoinFlip.Flip.Value = true

										CrowdCheer:Play()

										TutorialText.Visible = true
										typewrite(TutorialText, "It seems the ".. LocalPlayer.ValuesGame.TeamName.Value.." won the coin toss!")
									elseif chance <= 50 then
										CoinFlip.Flip.Value = true

										CrowdAw:Play()

										TutorialText.Visible = true
										typewrite(TutorialText, "The ".. LocalPlayer.ValuesGame.TeamName.Value.." lost the coin toss. ")
									end
								end)

								CoinFlip.Flip.Changed:Connect(function(plr)
									task.wait(3)
									local CamTween4 = TweenService:Create(Camera,TweenInfo.new(
										3,
										Enum.EasingStyle.Quad,
										Enum.EasingDirection.In),
										{
											CFrame = GameCameras.Camera4.CFrame
										})

									CamTween4:Play()
									typewrite(TutorialText, "The game is underway here at " .. LocalPlayer.ValuesGame.TeamName.Value.. " field!")

									task.wait(3)

									TutorialText.Visible = false
									CameraNormal()

									if PlayerGui.Player.Skip.Value.Value == true then
									else
										ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer(plr)
										PlayerGui.Player.GameUI.Visible = true
										PlayerGui.Player.GameUI.TimeFrame.Quarter.Value += 1
									end
								end)
							end
						end)
					end
				end
			end)

			table.insert(activeConnections, connection)
		end
	end)
		
	
end)

so here the code, but when i start the following game after the first, it does not start it.

1 Like

I’ll make sure to fix that.
I never checked that out.

1 Like

you can try this

--Client 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local LocalPlayer = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera

local activeConnections = {} -- Table to store all active connections
local buttonClicked = false -- Flag to prevent duplicate clicks

-- Function to add connections to the activeConnections table
local function addConnection(connection)
    table.insert(activeConnections, connection)
end

-- Function to disconnect all active connections
local function disconnectAll()
    for _, conn in ipairs(activeConnections) do
        conn:Disconnect()
    end
    activeConnections = {} -- Reset the table
end

-- Function to handle the start of the game
local function startGame()
    -- Prevent duplicate clicks
    if buttonClicked then return end
    buttonClicked = true

    -- Example UI changes and initial setup
    PlayerGui.MainFrame.Gamestart.Visible = false
    PlayerGui.MainFrame.Visible = false

    -- Fire server to start the game
    ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote:FireServer()

    -- Listen for game data from the server
    disconnectAll() -- Clear any lingering connections before reconnecting
    addConnection(ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnClientEvent:Connect(function(player)
        -- Game setup logic here
        print("Game started for player:", player.Name)
        
        -- Camera and UI setup (Example)
        local Teamname = player.TeamName -- Fetch team name
        local GameCameras = workspace:WaitForChild("Tycoon").Tycoons:WaitForChild(Teamname).Essentials.GamedayCameras

        Camera.CameraType = Enum.CameraType.Scriptable
        local camTween = TweenService:Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.In), { CFrame = GameCameras.Camera1.CFrame })
        camTween:Play()
        camTween.Completed:Wait()

        -- Example UI updates
        PlayerGui.Player.Skip.Visible = true
        PlayerGui.Player.Skip.MouseButton1Click:Connect(function()
            -- Skip logic here
            PlayerGui.Player.Skip.Visible = false
            PlayerGui.Player.GameUI.Visible = true
            ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer()
        end)

        -- Cleanup connections at the end of the game
        camTween.Completed:Wait(function()
            disconnectAll() -- Disconnect all events when the game ends
            buttonClicked = false -- Reset flag for new game
        end)
    end))
end

-- Connect the button to start the game
addConnection(PlayerGui.MainFrame.Gamestart.Yes.MouseButton1Click:Connect(startGame))
--Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Function to handle game start
ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnServerEvent:Connect(function(player)
    print("Starting game for:", player.Name)
    
    -- Fire event back to the client to initiate game setup
    ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote:FireClient(player)
end)

I’m pretty sleepy atm sorry for the delay.

1 Like

Your all good, the client script you sent only contains a little of the scripting of what i want to happen where would be the best place in there to add what I had so it all can playout then disconnect, and send to the server to play the game. for an example when i start game it doesn’t play the starting cutscene and then sends to the server for the game to playout.

1 Like
local activeConnections = {}
local buttonClicked = false
local connection

-- Function to manage connections
local function addConnection(conn)
    table.insert(activeConnections, conn)
end

local function cleanupConnections()
    for _, conn in ipairs(activeConnections) do
        if conn.Connected then
            conn:Disconnect()
        end
    end
    activeConnections = {}
end

-- Skip Button Logic (connected once)
local skipConnection = PlayerGui.Player.Skip.MouseButton1Click:Connect(function()
    PlayerGui.Player.GameUI.Visible = true
    PlayerGui.Player.Skip.Visible = false
    PlayerGui.Player.Skip.Value.Value = true
    ClickUI:Play()
    typewrite(TutorialText, "")
    TutorialText.Text = ""
    TutorialText.Visible = false
    CameraNormal()
    ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer()
    SoundService.Gameday:WaitForChild("Spotlights"):Stop()
end)
addConnection(skipConnection)

-- Main Game Logic
MainFrame.Gamestart.Yes.MouseButton1Click:Connect(function()
    if buttonClicked then return end
    buttonClicked = true

    cleanupConnections() -- Clean up old connections

    MainFrame.Gamestart.Visible = false
    MainFrame.Visible = false

    -- Connection to handle game start
    connection = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnClientEvent:Connect(function(player)
        if LocalPlayer.ValuesGame.Practice.Value == false and LocalPlayer.ValuesGame.Game.Value == false then
            ClickUI:Play()
            BlurTween()
            MainFrame.Visible = false
            task.wait(5)
            ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData:FireServer(player)

            -- Fetch team data logic
            local connection2 = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData.OnClientEvent:Connect(function(Teamname)
                local GameCameras = Workspace:WaitForChild("Tycoon").Tycoons:WaitForChild(Teamname).Essentials.GamedayCameras
                Camera.CameraType = Enum.CameraType.Scriptable

                local CamTween1 = TweenService:Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
                    CFrame = GameCameras.Camera1.CFrame
                })
                CamTween1:Play()
                StadiumAmbience:Play()
                CamTween1.Completed:Wait()

                TutorialText.Text = ""
                TutorialText.Visible = true
                UnBlurTween()
                task.wait(3)
                PlayerGui.Player.Skip.Visible = true

                -- Coin Flip Logic
                local CoinFlip = PlayerGui.Player.CoinFlip
                CoinFlip.Visible = true

                local headsConnection = CoinFlip.Heads.MouseButton1Click:Connect(function()
                    CoinFlip.Visible = false
                    ClickUI:Play()
                    local chance = math.random(1, 100)
                    if chance > 50 then
                        CoinFlip.Flip.Value = true
                        CrowdCheer:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "It seems the " .. LocalPlayer.ValuesGame.TeamName.Value .. " won the coin toss!")
                    else
                        CoinFlip.Flip.Value = true
                        CrowdAw:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "The " .. LocalPlayer.ValuesGame.TeamName.Value .. " lost the coin toss.")
                    end
                end)
                addConnection(headsConnection)

                local tailsConnection = CoinFlip.Tails.MouseButton1Click:Connect(function()
                    CoinFlip.Visible = false
                    ClickUI:Play()
                    local chance = math.random(1, 100)
                    if chance > 50 then
                        CoinFlip.Flip.Value = true
                        CrowdCheer:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "It seems the " .. LocalPlayer.ValuesGame.TeamName.Value .. " won the coin toss!")
                    else
                        CoinFlip.Flip.Value = true
                        CrowdAw:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "The " .. LocalPlayer.ValuesGame.TeamName.Value .. " lost the coin toss.")
                    end
                end)
                addConnection(tailsConnection)

                local flipChangeConnection = CoinFlip.Flip.Changed:Connect(function()
                    task.wait(3)
                    local CamTween4 = TweenService:Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
                        CFrame = GameCameras.Camera4.CFrame
                    })
                    CamTween4:Play()
                    typewrite(TutorialText, "The game is underway here at " .. LocalPlayer.ValuesGame.TeamName.Value .. " field!")
                    task.wait(3)
                    TutorialText.Visible = false
                    CameraNormal()

                    if not PlayerGui.Player.Skip.Value.Value then
                        ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer()
                        PlayerGui.Player.GameUI.Visible = true
                        PlayerGui.Player.GameUI.TimeFrame.Quarter.Value += 1
                    end
                end)
                addConnection(flipChangeConnection)
            end)
            addConnection(connection2)
        end
    end)
    addConnection(connection)
end)

i added in some more of the logic i hope this helps

1 Like

thank you i appreciate that, for some odd reason it doesn’t seem to transition into the cutscene here ill show what I mean.,

1 Like

this code turned it on but after the second time around just duplicated the start to finish of the game making it go crazy

1 Like

I think you meant to reply to @HolyGenki, but I’ll try to help as well

Essentially, make sure to disconnect the connections after the cutscene has finished playing, but use a debounce to make sure that new connections aren’t created while the cutscene is playing

2 Likes

I Thought this was the case as well, I’m so unrealistically sleepy thou, I figured i was automatically wrong XD. Just hoping I can help, I’m new to trying to help people in the forums tho. I made a coffee, i almost feel as if there parts of the script I’m just not seeing and maybe that’s why i can’t fully determine the issue. I got coffee brewing tho so XD

2 Likes

same here it’s 6:27 am, been trying to solve this since 1am.

1 Like

I want to say this should work better

local activeConnections = {}
local buttonClicked = false
local connection
local skipConnection

-- Function to manage connections
local function addConnection(conn)
    table.insert(activeConnections, conn)
end

local function cleanupConnections()
    for _, conn in ipairs(activeConnections) do
        if conn.Connected then
            conn:Disconnect()
        end
    end
    activeConnections = {}
end

-- Function to reset the game state
local function resetGameState()
    PlayerGui.Player.GameUI.Visible = false
    PlayerGui.Player.Skip.Visible = false
    PlayerGui.Player.Skip.Value.Value = false
    CoinFlip.Visible = false
    TutorialText.Text = ""
    TutorialText.Visible = false
    buttonClicked = false
end

-- Skip Button Logic (connected once)
if not skipConnection then
    skipConnection = PlayerGui.Player.Skip.MouseButton1Click:Connect(function()
        PlayerGui.Player.GameUI.Visible = true
        PlayerGui.Player.Skip.Visible = false
        PlayerGui.Player.Skip.Value.Value = true
        ClickUI:Play()
        typewrite(TutorialText, "")
        TutorialText.Text = ""
        TutorialText.Visible = false
        CameraNormal()
        ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer()
        SoundService.Gameday:WaitForChild("Spotlights"):Stop()
    end)
    addConnection(skipConnection)
end

-- Main Game Logic
MainFrame.Gamestart.Yes.MouseButton1Click:Connect(function()
    if buttonClicked then return end
    buttonClicked = true

    cleanupConnections() -- Clean up old connections

    MainFrame.Gamestart.Visible = false
    MainFrame.Visible = false

    -- Connection to handle game start
    connection = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.OfficialGameRemote.OnClientEvent:Connect(function(player)
        if LocalPlayer.ValuesGame.Practice.Value == false and LocalPlayer.ValuesGame.Game.Value == false then
            ClickUI:Play()
            BlurTween()
            MainFrame.Visible = false
            task.wait(5)
            ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData:FireServer(player)

            -- Fetch team data logic
            local connection2 = ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.FetchTeamData.OnClientEvent:Connect(function(Teamname)
                local GameCameras = Workspace:WaitForChild("Tycoon").Tycoons:WaitForChild(Teamname).Essentials.GamedayCameras
                Camera.CameraType = Enum.CameraType.Scriptable

                local CamTween1 = TweenService:Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
                    CFrame = GameCameras.Camera1.CFrame
                })
                CamTween1:Play()
                StadiumAmbience:Play()
                CamTween1.Completed:Wait()

                TutorialText.Text = ""
                TutorialText.Visible = true
                UnBlurTween()
                task.wait(3)
                PlayerGui.Player.Skip.Visible = true

                -- Coin Flip Logic
                local CoinFlip = PlayerGui.Player.CoinFlip
                CoinFlip.Visible = true

                local headsConnection = CoinFlip.Heads.MouseButton1Click:Connect(function()
                    CoinFlip.Visible = false
                    ClickUI:Play()
                    local chance = math.random(1, 100)
                    if chance > 50 then
                        CoinFlip.Flip.Value = true
                        CrowdCheer:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "It seems the " .. LocalPlayer.ValuesGame.TeamName.Value .. " won the coin toss!")
                    else
                        CoinFlip.Flip.Value = true
                        CrowdAw:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "The " .. LocalPlayer.ValuesGame.TeamName.Value .. " lost the coin toss.")
                    end
                end)
                addConnection(headsConnection)

                local tailsConnection = CoinFlip.Tails.MouseButton1Click:Connect(function()
                    CoinFlip.Visible = false
                    ClickUI:Play()
                    local chance = math.random(1, 100)
                    if chance > 50 then
                        CoinFlip.Flip.Value = true
                        CrowdCheer:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "It seems the " .. LocalPlayer.ValuesGame.TeamName.Value .. " won the coin toss!")
                    else
                        CoinFlip.Flip.Value = true
                        CrowdAw:Play()
                        TutorialText.Visible = true
                        typewrite(TutorialText, "The " .. LocalPlayer.ValuesGame.TeamName.Value .. " lost the coin toss.")
                    end
                end)
                addConnection(tailsConnection)

                local flipChangeConnection = CoinFlip.Flip.Changed:Connect(function()
                    task.wait(3)
                    local CamTween4 = TweenService:Create(Camera, TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
                        CFrame = GameCameras.Camera4.CFrame
                    })
                    CamTween4:Play()
                    typewrite(TutorialText, "The game is underway here at " .. LocalPlayer.ValuesGame.TeamName.Value .. " field!")
                    task.wait(3)
                    TutorialText.Visible = false
                    CameraNormal()

                    if not PlayerGui.Player.Skip.Value.Value then
                        ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer()
                        PlayerGui.Player.GameUI.Visible = true
                        PlayerGui.Player.GameUI.TimeFrame.Quarter.Value += 1
                    end

                    -- Reset the game state
                    resetGameState()
                end)
                addConnection(flipChangeConnection)
            end)
            addConnection(connection2)
        end
    end)
    addConnection(connection)
end)

It’s so weird for me to try and diagnoses stuff I’m not running in studio myself XD Maybe i can get use to it tho :slight_smile:

1 Like

When I first learned to program, I was way to nervous to use though forums as silly as it may seem I spent the longest time learning blender (to 3D model) to relieve my stress XD it defiantly worked. I got really good at it I felt. although now I don’t seem to run into any programing issues ever myself, So I figured I’d try to help others :),

1 Like
if not PlayerGui.Player.Skip.MouseButton1Click.Connection then

Got an error
Screenshot 2025-01-20 063540

1 Like

its great to hear that, I’ve always known small amounts of code to make very simple games, got some pretty popular games off of it, got to learn a lot more past 2 years, now i have a passion in all areas of game development and, im going into college as a computer science major

1 Like
local skipConnection

-- Ensure Skip Button Logic is connected only once
if not skipConnection then
    skipConnection = PlayerGui.Player.Skip.MouseButton1Click:Connect(function()
        PlayerGui.Player.GameUI.Visible = true
        PlayerGui.Player.Skip.Visible = false
        PlayerGui.Player.Skip.Value.Value = true
        ClickUI:Play()
        typewrite(TutorialText, "")
        TutorialText.Text = ""
        TutorialText.Visible = false
        CameraNormal()
        ReplicatedStorage.Remotes.Tycoon_Function_Remotes.Gametime.StartGame:FireServer()
        SoundService.Gameday:WaitForChild("Spotlights"):Stop()
    end)
    addConnection(skipConnection)
end

i think this what is causing the error try this

1 Like

When i go to start game it doesn’t start like before

1 Like