Shutdown Script Not Working?

Hello there. So I am using a big trusted edited version of Merely’s Soft Shutdown Script. It is from TheNexusAvenger, and it works until it is time to make the gui disappear which does not happen.
Here is the script he/she made:


local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local RunService = game:GetService("RunService")
local TeleportService = game:GetService("TeleportService")



--Set up teleport arrival.
TeleportService.LocalPlayerArrivedFromTeleport:Connect(function(Gui,Data)
	if Data and Data.IsTemporaryServer then
		--If it is a temporary server, keep showing the Gui, wait, then teleport back.
		Gui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui",10^99)
		StarterGui:SetCore("TopbarEnabled",false)
		StarterGui:SetCoreGuiEnabled("All",false)
		wait(5)
		TeleportService:Teleport(Data.PlaceId,Players.LocalPlayer,nil,Gui)
	else
		--If the player is arriving back from a temporary server, remove the Gui.
		if Gui and Gui.Name == "SoftShutdownGui" then Gui:Destroy() end
	end
end)



--Anything that can cause this to yeild will prevent teleport data being recieved.
local RenderStepped = RunService.RenderStepped
local StartShutdown = game.ReplicatedStorage:WaitForChild("StartShutdown")
local CreateTeleportScreen = require(script:WaitForChild("TeleportScreenCreator"))

--Set up event for when the server is shutting down.
StartShutdown.OnClientEvent:Connect(function()
	--Create the Gui and have it semi-transparent for 1 second.
	local Gui,Background = CreateTeleportScreen()
	Background.BackgroundTransparency = 0.5
	Gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
	wait(1)
	
	--Tween the transparency to 0.
	local Start = tick()
	local Time = 0.5
	while tick() - Start < Time do
		local Dif = tick() - Start
		local Ratio = Dif/Time
		Background.BackgroundTransparency = 0.5 * (1 - Ratio)
		RenderStepped:Wait()
	end
	Background.BackgroundTransparency = 0
end)

And I get this error, don’t know if it has anything to do with it:

1 Like

Greetings, sometimes LocalScripts load up before the core gui so you need to make it wait until the gui arrives, here is the piece which should replace the errored line:

local currentTime = tick()

repeat wait() until tick() - currentTime > 5 or pcall(game.StarterGui.SetCore, game.StarterGui,  "TopbarEnabled", false) end

Didn’t test it out, let me know if it works!

1 Like

This does not seem to go on line 15. As you said to replace it with the error ed line.

Replace the line that’s erroring with that. It will repeat and not allow the script to go on until either 5 seconds have passed, or until CoreGui is fully loaded and SetCore() is able to be called.

I am still clueless, as I dont see anything close to that in the script.

At:

StarterGui:SetCore("TopbarEnabled",false)
local RunService = game:GetService("RunService")
local TeleportService = game:GetService("TeleportService")



--Set up teleport arrival.
TeleportService.LocalPlayerArrivedFromTeleport:Connect(function(Gui,Data)
	if Data and Data.IsTemporaryServer then
		--If it is a temporary server, keep showing the Gui, wait, then teleport back.
		Gui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui",10^99)
		local currentTime = tick()
		
		repeat wait() until tick() - currentTime > 5 or pcall(game.StarterGui.SetCore, game.StarterGui,  "TopbarEnabled", false) end
		StarterGui:SetCoreGuiEnabled("All",false)
		wait(5)
		TeleportService:Teleport(Data.PlaceId,Players.LocalPlayer,nil,Gui)
	else
		--If the player is arriving back from a temporary server, remove the Gui.
		if Gui and Gui.Name == "SoftShutdownGui" then Gui:Destroy() end
	end
end)



--Anything that can cause this to yeild will prevent teleport data being recieved.
local RenderStepped = RunService.RenderStepped
local StartShutdown = game.ReplicatedStorage:WaitForChild("StartShutdown")
local CreateTeleportScreen = require(script:WaitForChild("TeleportScreenCreator"))

--Set up event for when the server is shutting down.
StartShutdown.OnClientEvent:Connect(function()
	--Create the Gui and have it semi-transparent for 1 second.
	local Gui,Background = CreateTeleportScreen()
	Background.BackgroundTransparency = 0.5
	Gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
	wait(1)
	
	--Tween the transparency to 0.
	local Start = tick()
	local Time = 0.5
	while tick() - Start < Time do
		local Dif = tick() - Start
		local Ratio = Dif/Time
		Background.BackgroundTransparency = 0.5 * (1 - Ratio)
		RenderStepped:Wait()
	end
	Background.BackgroundTransparency = 0
end)
It now errors at : else

Thank you @Ponzimus , that solved this same problem for me I just realized having in our game.
Your code is perfect, just there is an extra unnecessary “end” at the end of it.

So it should be:

local currentTime = tick()

repeat wait() until tick() - currentTime > 5 or pcall(game.StarterGui.SetCore, game.StarterGui,  "TopbarEnabled", false)