How to make gui only appear once

I have a script that creates a camera preview of the game, with a play button to exit the preview and actually play.

This appears for each player when they join, but there’s a problem; it also re-appears every single time the player dies (this will happen a lot as it is an obby). How can I make it so it only appears when the player joins, never again afterwards?

local player = game.Players.LocalPlayer;
local Char = player.Character or player.CharacterAdded:Wait();
local camera = workspace.CurrentCamera;
local startergui = game:GetService("StarterGui");

wait();
startergui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false);

repeat wait();
	camera.CameraType = Enum.CameraType.Scriptable;
until camera.CameraType == Enum.CameraType.Scriptable;
camera.CFrame = workspace.CameraPart1.CFrame;
local blur = Instance.new("BlurEffect");
blur.Parent = game.Lighting;
blur.Size = 1;

script.Parent.Frame.TextButton.MouseButton1Click:connect(function()
blur:Destroy()
	camera.CameraType = Enum.CameraType.Custom;

	script.Parent:Destroy();
	end);

Cheers.

Have you checked the GUI’s property called ResetOnSpawn?

Boolean flag!

local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local startergui = game:GetService("StarterGui")

wait()
startergui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

local guiShown = false

local function showGUI()
    if guiShown then
        return 
    end
    
    guiShown = true 
    
    repeat wait()
        camera.CameraType = Enum.CameraType.Scriptable
    until camera.CameraType == Enum.CameraType.Scriptable
    
    camera.CFrame = workspace.CameraPart1.CFrame
    
    local blur = Instance.new("BlurEffect")
    blur.Parent = game.Lighting
    blur.Size = 1
    
    script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
        blur:Destroy()
        camera.CameraType = Enum.CameraType.Custom
        
        script.Parent:Destroy()
    end)
end

showGUI()
2 Likes

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