How to make the Game wait until the player clicks on the button in a Cloned Gui

I have a system that when you die, the game shows you your score. The score Gui gets cloned but only appears for 1 second. Is there a way for the game to wait for the Player to click on the Button, and then the score Gui disappears?

function showResults(player)
	local resultsGUI = game.ServerStorage.GUIs.PostRunGUI:Clone()
	resultsGUI.Frame.DistanceValue.Text = player.RunStats.Distance.Value
	resultsGUI.Frame.CoinsValue.Text = player.RunStats.CoinsCollected.Value
	resultsGUI.Frame.ScoreValue.Text = player.leaderstats.Score.Value
	
	resultsGUI.Parent = player.PlayerGui
	
	resultsGUI.Frame.MainMenuBtn.MouseButton1Click:Connect(function()
		resultsGUI:Destroy()  -- This is what happens when the player clicks on the Button
	end)
end

Isn’t this doing exactly what you want?

the gui is only visible for 1 second and then disappears

function showResults(player)
	local resultsGUI = game.ServerStorage.GUIs.PostRunGUI:Clone()
	resultsGUI.Frame.DistanceValue.Text = player.RunStats.Distance.Value
	resultsGUI.Frame.CoinsValue.Text = player.RunStats.CoinsCollected.Value
	resultsGUI.Frame.ScoreValue.Text = player.leaderstats.Score.Value
	
	resultsGUI.Parent = player.PlayerGui
	
	resultsGUI.Frame.MainMenuBtn.MouseButton1Click:Connect(function()
		resultsGUI:Destroy()
	end)
end

function initialiseNewRun(player, delayTime, charExpected, showLastResults)
	if not path then
		while not path do
			wait()
		end
	end

	local lastResultsGUI = nil
	if showLastResults then
		lastResultsGUI = showResults(player)
	end

	if lastResultsGUI ~= nil then
		lastResultsGUI:Destroy()
	end

	if player and player.Parent then
		-- charExpected is needed to avoid calling LoadCharacter on players leaving the game
		if player.Character or charExpected == false then
			player:LoadCharacter()

			initialiseRunStats(player)

			local playersPath = path()
			lastActivePath[player.Name] = playersPath
			playersPath:init(player.Name)
		end
	end
end

Change the above to:

resultsGUI.Frame.MainMenuBtn.MouseButton1Click:Wait()
resultsGUI:Destroy()
1 Like

It’s working, thank you! . . .

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.