ExitButton GUI Problems

Hello to everyone stopping by to read this!

Yesterday I started on a little story project because its trending for the younger players in roblox and I wanted to see how it would turn out.

I am trying to make it where I can bring the “ExitButton” from ReplicatedStorage into the LocalPlayers PlayerGui, which I have, but the problem is that when I go back into the the elevator that I made the script for, instead of changing Parents again, it stays in ReplicatedStorage. Any ideas?

In order, here is my script, and then my local script:


Here is how it looks entering the elevator for the first time:

How it looks the second time:

Thank you for whoever decides to jump in to help!

3 Likes

The problem here has to do with replication, which you should read up on and get familiar with. The client cannot propagate changes to the server without a remote so the LocalScript parenting the Gui back to ReplicatedStorage is not seen by the server.

The proper fix here is to clone the Gui instead of reparenting it out of ReplicatedStorage, because not only does it affect the current player’s ability to get the Gui again but it also prevents others from getting it as well. Another proper fix is to not reparent the Gui at all and leave it in PlayerGui, changing the Enabled property based on whether or not the player should see the Gui.

I strongly recommend using the second suggestion and changing your entire system to function locally. That is, from StarterPlayerScripts, a script that will handle both when the player enters the elevator and needs the close button as well as when they click the exit button and need to leave it. You’ll also need a check in the Touched bit to see if the player from GetPlayerFromCharacter is equivalent to the LocalPlayer.

4 Likes

Thank you, I will check it out!

1 Like

Forgive me for somewhat avoiding the current problem and instead suggesting a different route, but have you thought to just clone the Exit Button into the PlayerGUI?

You’d definitely have to use a RemoteEvent to remove the Exit Button from the PlayerGUI due to it using a Local Script to remove an instance. However, that’d be easy to assist with if help was necessary.

1 Like

I had done that but then it would clone more than 1 ExitButton because there was no cooldown and I have no clue how to approach it. Alongside that, it would mess up the teleport back to the spawns and it makes no sense to me why it would do that.

1 Like

When you mean changing it all to locally, do you mean using a local script for the teleport into the elevator when it touches the doortp part and out when the ExitButton is clicked? Im trying my best to understand.

1 Like

if not player.PlayerGui:FindFirstChild(“Exit Button”) then
— proceed to clone
end

Would this solve that multiple exit button problem?

1 Like

It might be my placing of it in the script, but it cloned several still.

local exit = workspace.Elevator1.ExitButton
local tp = workspace.Elevator1.Parts.Floor

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.Character.HumanoidRootPart.CFrame = tp.CFrame + Vector3.new(0,5,0)
exit:Clone().Parent = player.PlayerGui
if not player.PlayerGui:FindFirstChild(“ExitButton”) then
end
end
end)

1 Like

local exit = workspace.Elevator1.ExitButton
local tp = workspace.Elevator1.Parts.Floor

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.Character.HumanoidRootPart.CFrame = tp.CFrame + Vector3.new(0,5,0)
if not player.PlayerGui:FindFirstChild(“ExitButton”) then
exit:Clone().Parent = player.PlayerGui
end
end
end)

Just know that when you click that exit button with the current set up, it’ll only remove the Exit GUI from the client not the server. So if you plan on using this multiple times, make sure to create a remote event that’ll remove the Exit Button from the PlayerGui on the server and not just the client.

1 Like

How would I do that? And will it stop the problem of it not showing on the second entry of the elevator?

1 Like

1 Like

I found the fix I don’t know why I wasn’t thinking but I copied it from your solution.

1 Like

1

output

1 Like

I don’t know if I even placed any of this right so, Local script is the second photo. A script in serverscriptservice is at the top, and that’s the output.

1 Like

Your CloseRemote event requires a function, but you didn’t put one.

1 Like

I’m sorry, previous posts were garbage. Now I’m back on the computer.

First, insert a RemoteEvent. Place that RemoteEvent inside of ReplicatedStorage. Name it CloseEvent

– Local Script
-- Reference the Event
local Event = game:GetService("ReplicatedStorage"):WaitForChild("CloseEvent")

Add this line at the point of time you’d like the Exit Button GUI to go away.
Event:FireServer("ExitButton")

– Server Script Code
local Event = game:GetService("ReplicatedStorage"):WaitForChild("CloseEvent")

CloseRemote.OnServerEvent:Connect(function(player, GUI)
local PlayerGui = player:WaitForChild(“PlayerGui”)
PlayerGui:FindFirstChild(GUI):Destroy()
end)

Let me know how this goes for you! :slight_smile:

2 Likes

[ServerScriptService.Script:2: attempt to index nil with ‘OnServerEvent’]

Where does CloseRemote come from?

I think he means Event.OnServerEvent:Connect(function(player, GUI)

1 Like

Thank you all so much its working!

1 Like