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:
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.
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.
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.
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.
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)
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.
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.