Parenting a Gui to ReplicatedStorage then back to PlayerGui breaks connections

Hello, I’m having an issue with a Gui, when I try to parent it the first time to PlayerGui it works fine without any issues, but when I parent it to ReplicatedStorage and then back to PlayerGui it no longer works. Does anyone know why this might happen?

Here are the scripts:

LocalScript in the Tool I’m using to parent the Gui.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Components = ReplicatedStorage:WaitForChild("Components")
local Equipment = Components:WaitForChild("Equipment")
local Scientist = Equipment:WaitForChild("Scientist")
local Gui = Scientist:WaitForChild("Gui")

local StarterGui = game:GetService("StarterGui")

local Tool = script.Parent
local Clipboard = Gui:WaitForChild("ClipboardGui")

local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild("Humanoid")

Tool.Equipped:Connect(function()
	Clipboard.Enabled = true
	Clipboard.Parent = Player.PlayerGui
end)

Tool.Unequipped:Connect(function()
	Clipboard.Enabled = false
	Clipboard.Parent = Gui
end)

Humanoid.Died:Connect(function()
	Clipboard.Enabled = false
	Clipboard.Parent = Gui
end)

LocalScript inside the Gui that doesn’t work after re-parenting to PlayerGui

local Main = script.Parent
local CurrentPage = Main:WaitForChild("CurrentPage")

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local CURRENT_PAGE = 1
local MAX_PAGES = 10

CurrentPage.Text = string.format("Page %s", CURRENT_PAGE)

for i = CURRENT_PAGE, MAX_PAGES, 1 do
	if #Main.Pages:GetChildren() >= MAX_PAGES then return end
	
	local template = script.Template:Clone()
	template.Name = tostring(i)
	if i == CURRENT_PAGE then
		template.Content.Visible = true
		template.Title.Visible = true
	end
	template.Parent = Main.Pages
end

local function HideAllPages()
	for _, page in pairs(Main.Pages:GetDescendants()) do
		if page:IsA("TextBox") then
			page.Visible = false
		end
	end
end

local function ShowPage()
	local Page = Main.Pages[CURRENT_PAGE]
	for _, page in pairs(Page:GetChildren()) do
		if page:IsA("TextBox") then
			page.Visible = true
		end
	end
end

Main.NextPage.MouseButton1Down:Connect(function()
	CURRENT_PAGE += 1
	Main.CurrentPage.Text = string.format("Page %s", CURRENT_PAGE)

	HideAllPages()
	ShowPage()

	if CURRENT_PAGE >= MAX_PAGES then
		Main.NextPage.Visible = false
		Main.PageBack.Visible = true
		return
	end

	if CURRENT_PAGE > 1 then
		Main.PageBack.Visible = true
	end

end)

Main.PageBack.MouseButton1Down:Connect(function()
	CURRENT_PAGE -= 1
	Main.CurrentPage.Text = string.format("Page %s", CURRENT_PAGE)

	HideAllPages()
	ShowPage()

	if CURRENT_PAGE <= 1 then
		Main.PageBack.Visible = false
		Main.NextPage.Visible = true
		return
	end

	if CURRENT_PAGE > 1 and CURRENT_PAGE <= MAX_PAGES then
		Main.NextPage.Visible = true
	end
end)

If anyone knows why this is happening please tell me, I’ve been trying to figure it out for the past few hours with no success. And yes, I have tried using a script to parent it aswell and that didn’t work either.

instead of placing it in ReplicatedStorage, add the gui in the tool, then make clone it into player gui, then make it visible, like this

local player = game.Players.LocalPlayer
local tool = toolLol -- whatever script.Parent or idk
local toolGUI = weapon:WaitForChild("whatever your gui is named")

tool.Equipped:Connect(function()
    local newGUI = wepGUI:Clone()
    newGUI.Parent = player.PlayerGUI
    newGUI.Enabled = true
end)
2 Likes

I fixed it finally jesusss that was such a pain. The issue with it not working was this line

if #Main.Pages:GetChildren() >= MAX_PAGES then return end 

It would cease the script from running once the pages were created, what I did was change it to this now it all works fine

if #Main.Pages:GetChildren() <= MAX_PAGES then

Why I didn’t want it parented to the tool is because when the player dies the tool also gets reset meaning the gui gets destroyed aswell, and this is a clipboard with text put in by the player so it needs to stay the exact same when they equip it again.

1 Like

Oof, remember to always proofread!