ScreenGui not disappearing after 8 seconds

Hello,

So basically in my game there’s a pad that teleports you to a part located inside a hidden black box under the next location where your character waits for 8 seconds meanwhile the game loads the surroundings. In said time waiting, you’ll see a ScreenGui that says “Loading, please wait,” but despite adding a line to have it removed at the end of the script after 8 seconds it won’t do so. Before I show the setup and such, here’s a clip of what’s going on:

I know the teleportation script works fine as I can hear the music in the background playing meaning you’ve fully loaded into the next location and ready to continue your way. However the ScreenGui doesn’t want to disappear, am I missing something?

The setup:

The invisible pad inside Workspace that teleports you once you get close to the portal:

The code inside “Pad3tpScript” Script (nothing too crazy):

local WaitingPart = game.Workspace.WaitingPart
local LoadingSound = game.Workspace.loading
local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Touched:Connect(function(touchPart)
	if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
		local Character = touchPart.Parent
		local teleportLocation = CFrame.new(WaitingPart.CFrame.X, WaitingPart.CFrame.Y + 5, WaitingPart.CFrame.Z)
		local player = game.Players:GetPlayerFromCharacter(touchPart.Parent)
		Character:SetPrimaryPartCFrame(teleportLocation)
		local teleportingValue = Character.currentlyTeleporting
		teleportingValue.Value = true
		LoadingSound:Play()
		task.wait(8)
		teleportingValue.Value = false
	end
end)

The code inside the “ShowGUI” Script (pretty simple stuff once again):

local GUI = script.loadingscreen
script.Parent.Touched:connect(function (hit)
 if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
      local plr = game.Players[hit.Parent.Name]
 if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
			GUI:Clone().Parent = plr.PlayerGui
			task.wait(8)
			GUI.Enabled = false
 end
 end
end)

Here’s the setup for the part you get teleported to to wait for 8 seconds meanwhile your surroundings load in just in case it’s needed to see:

The code inside “Pad4tpScript” (pretty much the first script but with a few things different):

local Pad4 = game.Workspace.Pad4
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUI = game.Workspace.Pad3.ShowGUI

function onTouched(hit)
	hit.Parent.HumanoidRootPart.Anchored = true
	local humanoid = hit.Parent:findFirstChild("Humanoid")
	if humanoid~=nil then
		humanoid.WalkSpeed = 0
		task.wait(8)
		local Character = hit.Parent
		local teleportLocation = CFrame.new(Pad4.CFrame.X, Pad4.CFrame.Y + 5, Pad4.CFrame.Z)
		Character:SetPrimaryPartCFrame(teleportLocation)
		humanoid.WalkSpeed = 13
	end
end

script.Parent.Touched:Connect(onTouched)

I’ve also tried GUI:Destroy() but not even that seems to get rid of it. I’d appreciate some help on this little issue as it’s the only problem I’m currently experiencing with teleportation to the next area!

Hello, the reason it isn’t disappearing is because you’re setting the Enabled property to false on the GUI that you’re cloning, not the GUI that you parented to the PlayerGui. I suggest making a variable of the cloned GUI and then disabling the GUI through the variable.

local clonedGUI = GUI:Clone()
clonedGUI.Parent = plr.PlayerGui
task.wait(8)
clonedGUI.Enabled = false

Hope this helps! :+1:

2 Likes

Alright, so I believe the problem is that you have not added a debounce, thus the screen does not go away, after the time period. Let me explain what is happening right now.

  • When the player touches the part and you tell the script to show something in the player’s screen, the event will start repeating if debounce is not added, now I see you have used this
    if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
    Would you mind telling me what the name of the UI is, i might be able to help you out then,
1 Like

Would you also mind sending an SS of the output?

Ohhh makes sense, yeah the UI is called “loadingscreen”. It can also be seen in the second image I provided as well as its children.

That’s what I found strange, I didn’t see any warning nor error in the output.

Thanks! It worked :slight_smile: Before I mark your answer as solved though, would you happen to know how to unanchor the HumanoidRootPart.in the end of the “Pad4tpScript” script?

local Pad4 = game.Workspace.Pad4
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUI = game.Workspace.Pad3.ShowGUI

function onTouched(hit)
	hit.Parent.HumanoidRootPart.Anchored = true
	local humanoid = hit.Parent:findFirstChild("Humanoid")
	if humanoid~=nil then
		humanoid.WalkSpeed = 0
		task.wait(10)
		local Character = hit.Parent
		local teleportLocation = CFrame.new(Pad4.CFrame.X, Pad4.CFrame.Y + 5, Pad4.CFrame.Z)
		Character:SetPrimaryPartCFrame(teleportLocation)
		humanoid.WalkSpeed = 13
		
	end
end

script.Parent.Touched:Connect(onTouched)

It’s anchored meanwhile you’re waiting but once you load in you’re standing still unable to actually move around. What would I add at the end?

I tried doing something like hit.Pad4.HumanoidRootPart.Anchored = false in line 14 but it didn’t seem to work lol.

I recommend making a new post for that since I’m pretty sure that counts as off-topic, I just joined the forums like a few hours ago so I don’t know. But what you tried should work as long as you set it to false.

Edit: Nvm it wouldn’t work, but use the Character variable.

1 Like