Button not cloning to PlayerGUI

I’m attempting to clone a button from Replicated Storage into the player’s playerGUI. However, it doesn’t seem to be doing so at all.

local _Quests = require(game.ReplicatedStorage.GameConfig)

plr.CharacterAdded:Connect(function(chr)
		
	local questsFolder = plr:WaitForChild("Quests")
	local QuestButtons = _Quests.QuestButtons 

	for _, questInstance in pairs(questsFolder:GetChildren()) do
		local questName = questInstance.Name
		local clonedButton = QuestButtons:FindFirstChild(questName):Clone()
		clonedButton.Parent = plr:WaitForChild("PlayerGui").Quests.Frame.Scrolling
	end

--- (... Rest of character added function...)

It is in fact getting the questNames and everything. It just seems to fail at actually cloning and parenting them. What could be going wrong? This is a server script.

1 Like

I made a similar code and everything seems to be working fine for me, here is the code:

local RSS = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Chr)
		Plr.Chatted:Connect(function(msg)
			if msg == "clonegui" then
				local GUI = script.TestGUI
				local GUIClone = GUI:Clone()
				GUIClone.Parent = Plr:WaitForChild("PlayerGui")
				local GUI_CLONE = RSS:WaitForChild("TestGUI")
				GUI_CLONE.Parent = Plr:WaitForChild("PlayerGui")
				
			end
		end)
	end)
end)

This is a server sided script in server script service. Both of the GUI cloned regardless of the location of said UI.

I would say double check your file names and make sure it matches; also, I’ve realize that you’ve not declared the player object from the player added event, so maybe you forgot about that or did not include that part, either way, I just wanted to double check since your actual cloning and parenting of the UI should be correct.

1 Like

Found out that the button was getting destroyed or being set to nil immediately after despite not being referenced anywhere else. Not sure why.