How to make gui stay upon leaving

I’m trying to make it so that when the character comes back their gui from the quest they were on stays but i dont know how. I already have the quest index saved so it’s still as if im on the quests but the gui isnt there and it only appears if I had completed a previous quests and are assigned a new one then it leaves again upon leaving the game. Like is there a way to preserve the frames or something I’ve treid calling the addtoquestlist function upon joining but i js get an error then again I might not be calling it right.

		-- Check if the quest has valid stats or requirements
		if not self.Stats and not self.Class and not self.Status and not self.Genetics then return end

		local PlrGui = Player.PlayerGui
		local QuestsGui = PlrGui:FindFirstChild("Quests")
		local QFrame = QuestsGui and QuestsGui:FindFirstChild("QuestsFrame")
		local Bg = QFrame and QFrame:FindFirstChild("Bg")

		if not Bg then
			warn("Quest UI elements not found for player: " .. Player.Name)
			return
		end

		local MainQuests = Bg:FindFirstChild("MainQuests")
		local QuestNameLabel = MainQuests and MainQuests:FindFirstChild("QuestName")

		local Frame = MainQuests and MainQuests:FindFirstChild("Frame")
		local BaseStatFrame = Frame and Frame:FindFirstChild("BaseProgressFrame")
		local RewardsFrame = Frame and Frame:FindFirstChild("RewardsFrame")

		if not (QuestNameLabel and Frame and BaseStatFrame) then
			warn("Quest UI components missing for player: " .. Player.Name)
			return
		end

		QuestNameLabel.Text = self.Name

		-- Clear previous content
		for _, Child in ipairs(Frame:GetChildren()) do
			if Child ~= BaseStatFrame and Child ~= RewardsFrame and Child:IsA("Frame") then
				Child:Destroy()
			end
		end

		local TweenService = game:GetService("TweenService")
		local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

		-- Update Stat Progress Bars
		if self.Stats then
			for Stat, Req in pairs(self.Stats) do
				local Clone = BaseStatFrame:Clone()
				local ProgLabel = Clone:FindFirstChild("ProgressLabel")
				local Fill = Clone:FindFirstChild("Fill")

				local QStat = Player.PhysicalStats:FindFirstChild(Stat)
				if not (ProgLabel and Fill and QStat) then
					warn("Quest stat or progress elements missing for player: " .. Player.Name)
					return
				end

				ProgLabel.Text = abbreviateNumber(QStat.Value) .. "/" .. abbreviateNumber(Req) .. " " .. Stat
				local Ratio = math.min(QStat.Value / Req, 1)

				local tween = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(Ratio, 0, 1, 0)})
				tween:Play()

				QStat.Changed:Connect(function()
					ProgLabel.Text = abbreviateNumber(QStat.Value) .. "/" .. abbreviateNumber(Req) .. " " .. Stat
					Ratio = math.min(QStat.Value / Req, 1)
					local tweenUpdate = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(Ratio, 0, 1, 0)})
					tweenUpdate:Play()
				end)

				Clone.Name = Stat .. "ProgBar"
				Clone.Visible = true
				Clone.Parent = Frame
			end
		end

		-- Display Class Requirement
		if self.Class then
			local ClassReq = Player.leaderstats.Class.Value
			local ClassRequirement = self.Class

			local Clone = BaseStatFrame:Clone()
			local ProgLabel = Clone:FindFirstChild("ProgressLabel")
			local Fill = Clone:FindFirstChild("Fill")

			ProgLabel.Text = "Elevate to " .. ClassRequirement
			local Ratio = (ClassReq == ClassRequirement) and 1 or 0
			local tween = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(Ratio, 0, 1, 0)})
			tween:Play()

			Player.leaderstats.Class.Changed:Connect(function()
				local newClass = Player.leaderstats.Class.Value
				ProgLabel.Text = "Elevate to " .. ClassRequirement
				local newRatio = (newClass == ClassRequirement) and 1 or 0
				local tweenUpdate = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(newRatio, 0, 1, 0)})
				tweenUpdate:Play()
			end)

			Clone.Name = "ClassReqProgBar"
			Clone.Visible = true
			Clone.Parent = Frame
		end

		-- Display Status Requirement
		if self.Status then
			local StatusReq = Player.leaderstats.Status.Value
			local StatusRequirement = self.Status

			local Clone = BaseStatFrame:Clone()
			local ProgLabel = Clone:FindFirstChild("ProgressLabel")
			local Fill = Clone:FindFirstChild("Fill")

			ProgLabel.Text = "Become a " .. StatusRequirement
			local Ratio = (StatusReq == StatusRequirement) and 1 or 0
			local tween = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(Ratio, 0, 1, 0)})
			tween:Play()

			Player.leaderstats.Status.Changed:Connect(function()
				local newStatus = Player.leaderstats.Status.Value
				ProgLabel.Text = "Become a " .. StatusRequirement
				local newRatio = (newStatus == StatusRequirement) and 1 or 0
				local tweenUpdate = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(newRatio, 0, 1, 0)})
				tweenUpdate:Play()
			end)

			Clone.Name = "StatusReqProgBar"
			Clone.Visible = true
			Clone.Parent = Frame
		end

		-- Display Genetics Requirement
		if self.Genetics then
			local GeneticsReq = Player.leaderstats.Genetics and Player.leaderstats.Genetics.Value
			local GeneticsRequirement = self.Genetics

			if GeneticsReq then
				local Clone = BaseStatFrame:Clone()
				local ProgLabel = Clone:FindFirstChild("ProgressLabel")
				local Fill = Clone:FindFirstChild("Fill")

				ProgLabel.Text = "Reach Genetics Level " .. GeneticsRequirement
				local Ratio = (GeneticsReq == GeneticsRequirement) and 1 or 0
				local tween = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(Ratio, 0, 1, 0)})
				tween:Play()

				Player.leaderstats.Genetics.Changed:Connect(function()
					local newGenetics = Player.leaderstats.Genetics.Value
					ProgLabel.Text = "Reach Genetics Level " .. GeneticsRequirement
					local newRatio = (newGenetics == GeneticsRequirement) and 1 or 0
					local tweenUpdate = TweenService:Create(Fill, tweenInfo, {Size = UDim2.new(newRatio, 0, 1, 0)})
					tweenUpdate:Play()
				end)

				Clone.Name = "GeneticsReqProgBar"
				Clone.Visible = true
				Clone.Parent = Frame
			end
		end

		-- Update Rewards Frame
		local TokensLabel = RewardsFrame:FindFirstChild("TokensLabel")
		if not TokensLabel then
			TokensLabel = Instance.new("TextLabel")
			TokensLabel.Name = "TokensLabel"
			TokensLabel.Size = UDim2.new(1, 0, 1, 0)
			TokensLabel.BackgroundTransparency = 1
			TokensLabel.TextColor3 = Color3.new(1, 1, 1)
			TokensLabel.TextScaled = true
			TokensLabel.Parent = RewardsFrame
		end
		TokensLabel.Text = "Reward: " .. abbreviateNumber(self.Rewards.Tokens) .. " Tokens"

		RewardsFrame.Visible = true
	end


	-- Remove or hide quest UI if all quests are completed
	if State == "NoMoreQuests" then
		local PlrGui = Player.PlayerGui
		local QuestsGui = PlrGui.Quests
		local QFrame = QuestsGui.QuestsFrame
		local MainQuests = QFrame.Bg.MainQuests
		local Frame = MainQuests.Frame
		for _, Child in ipairs(Frame:GetChildren()) do
			if Child:IsA("Frame") then
				Child:Destroy()
			end
		end
		local TokensLabel = Frame:FindFirstChild("TokensLabel")
		if TokensLabel then
			TokensLabel:Destroy()
		end
		MainQuests.QuestName.Text = "More quests coming soon!"
	end

	return newQuest```

If you like store every single property of the frames (what are you trying to preserve?) in a data store you might be able to.

It is never a good idea to save GUIs, let alone by their properties. It’s already difficult enough without the native ability to derive all the properties of a given instance. Instead, save the state that the GUI is relaying, then have the GUI relay that state once more

1 Like

there is literally a function in the ScreenGui: ResetOnDeath or something

calling addtoquestlist sounds like the right thing to do assuming that function does what its name suggests
could you perhaps tell us the error you encounter when you call it upon joining? its possible the issue is just that it runs before everything loads