Hello, im not the best at scripting so bare with me.
Let's say there is 1 screengui in StarterGui, with 2 frames inside of it. 1 frame being the loading frame, then another frame being the Main Menu. I want the main menu too appear after someone dies, but not the loading screen so they dont have too wait for it too load again. I also followed a tutorial for this main menu + loading screen. The tutorial link is:
https://www.youtube.com/watch?v=BbXHAF6OGRA&t
Main Handler Local Script- (Inside the ScreenGui)
local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() char:WaitForChild("HumanoidRootPart").Anchored = true local mouse = plr:GetMouse() local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CFrame = workspace.MenuComponents.CameraStartPosition.CFrame local tweenService = game:GetService("TweenService") local mainMenuGui = script.Parent local mainMenuBG = mainMenuGui:WaitForChild("MainMenuBackground") local playBtn = mainMenuBG:WaitForChild("PlayButton") local creditsBtn = mainMenuBG:WaitForChild("CreditsButton") local creditsBG = mainMenuBG:WaitForChild("CreditsBackground") local loadingScreenBG = mainMenuGui:WaitForChild("LoadingScreenBackground") local logo = loadingScreenBG:WaitForChild("Logo") local loadingBarBG = loadingScreenBG:WaitForChild("LoadingBarBG") local clippingFrame = loadingBarBG:WaitForChild("ClippingFrame") local loadingBar = clippingFrame:WaitForChild("LoadingBar") clippingFrame.Size = UDim2.new(0, 0, 1, 0) clippingFrame:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 5) clippingFrame:GetPropertyChangedSignal("Size"):Connect(function() loadingBar.Size = UDim2.new(1/clippingFrame.Size.X.Scale, 0, 1, 0) end) repeat wait() until clippingFrame.Size == UDim2.new(1, 0, 1, 0) local loadingScreenFade = tweenService:Create(loadingScreenBG, TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}) loadingScreenFade:Play() logo:TweenPosition(UDim2.new(0.5, 0, -0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2) loadingBarBG:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2) local originalCFrame = camera.CFrame local scaleFactor = 1000 game:GetService("RunService").RenderStepped:Connect(function() local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2) local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0) camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre) end) local playButtonClicked = false playBtn.MouseButton1Click:Connect(function() if playButtonClicked then return end playButtonClicked = true creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true) mainMenuBG:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 3, true) wait(3) char.HumanoidRootPart.Anchored = false game.Players.LocalPlayer.PlayerGui.SelectionGui.Enabled = true --char.HumanoidRootPart.CFrame = workspace.MenuComponents.SpawnPart.CFrame mainMenuGui.Enabled = false script.Disabled = true end) local creditsOpen = false creditsBtn.MouseButton1Click:Connect(function() if playButtonClicked then return end if creditsOpen then creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true) else creditsBG:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true) end creditsOpen = not creditsOpen end) local function hoverOnButton(btn) if playButtonClicked then return end local colourDarken = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(221, 221, 221)}) colourDarken:Play() end local function hoverOffButton(btn) if playButtonClicked then return end local colourNormal = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(255, 255, 255)}) colourNormal:Play() end playBtn.MouseEnter:Connect(function() hoverOnButton(playBtn) end) creditsBtn.MouseEnter:Connect(function() hoverOnButton(creditsBtn) end) playBtn.MouseLeave:Connect(function() hoverOffButton(playBtn) end) creditsBtn.MouseLeave:Connect(function() hoverOffButton(creditsBtn) end)
What I would do is something quite simple. Create a bool that basically is set to true once the loading screen is loaded. That bool will prevent the screen from appearing after the player dies. Additionally, I created an if statement that will load the loading screen if loaded == false
. If loaded == true
, then it should not load the loading screen. Let me know if you have any issues!
local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() char:WaitForChild("HumanoidRootPart").Anchored = true local mouse = plr:GetMouse() local loaded = false local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CFrame = workspace.MenuComponents.CameraStartPosition.CFrame local tweenService = game:GetService("TweenService") local mainMenuGui = script.Parent local mainMenuBG = mainMenuGui:WaitForChild("MainMenuBackground") local playBtn = mainMenuBG:WaitForChild("PlayButton") local creditsBtn = mainMenuBG:WaitForChild("CreditsButton") local creditsBG = mainMenuBG:WaitForChild("CreditsBackground") local loadingScreenBG = mainMenuGui:WaitForChild("LoadingScreenBackground") local logo = loadingScreenBG:WaitForChild("Logo") local loadingBarBG = loadingScreenBG:WaitForChild("LoadingBarBG") local clippingFrame = loadingBarBG:WaitForChild("ClippingFrame") local loadingBar = clippingFrame:WaitForChild("LoadingBar") if loaded == false then clippingFrame.Size = UDim2.new(0, 0, 1, 0) clippingFrame:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 5) clippingFrame:GetPropertyChangedSignal("Size"):Connect(function() loadingBar.Size = UDim2.new(1/clippingFrame.Size.X.Scale, 0, 1, 0) end) repeat wait() until clippingFrame.Size == UDim2.new(1, 0, 1, 0) local loadingScreenFade = tweenService:Create(loadingScreenBG, TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}) loadingScreenFade:Play() logo:TweenPosition(UDim2.new(0.5, 0, -0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2) loadingBarBG:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2) loaded = true end local originalCFrame = camera.CFrame local scaleFactor = 1000 game:GetService("RunService").RenderStepped:Connect(function() local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2) local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0) camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre) end) local playButtonClicked = false playBtn.MouseButton1Click:Connect(function() if playButtonClicked then return end playButtonClicked = true creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true) mainMenuBG:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 3, true) wait(3) char.HumanoidRootPart.Anchored = false game.Players.LocalPlayer.PlayerGui.SelectionGui.Enabled = true --char.HumanoidRootPart.CFrame = workspace.MenuComponents.SpawnPart.CFrame mainMenuGui.Enabled = false end) local creditsOpen = false creditsBtn.MouseButton1Click:Connect(function() if playButtonClicked then return end if creditsOpen then creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true) else creditsBG:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true) end creditsOpen = not creditsOpen end) local function hoverOnButton(btn) if playButtonClicked then return end local colourDarken = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(221, 221, 221)}) colourDarken:Play() end local function hoverOffButton(btn) if playButtonClicked then return end local colourNormal = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(255, 255, 255)}) colourNormal:Play() end playBtn.MouseEnter:Connect(function() hoverOnButton(playBtn) end) creditsBtn.MouseEnter:Connect(function() hoverOnButton(creditsBtn) end) playBtn.MouseLeave:Connect(function() hoverOffButton(playBtn) end) creditsBtn.MouseLeave:Connect(function() hoverOffButton(creditsBtn) end)
Hello. Thank you for the response. Am I supposed too put anything , like a value in the screengui? If not, I replaced the script with yours, and when I reset the loading screen still shows up. I was trying to make it so the loading screen shows up when the player joins, but not after the player dies. I need it so only the main menu to show up after the character dies.