I cant save a value in playerGui when player removing

Hi! I want to know that how do i save something in PlayerGui when player removing?

I want to save children in the

PlayerGui.Test.Queue

So I tried

game:GetService("Players").PlayerRemoving:Connect(function(Player)

local TargetGui = Player.PlayerGui.Test.Queue

local DataToSave = {}
	
	for i, v in pairs(TargetGui:GetChildren()()) do
		
		if v:IsA("Frame") then
			
			table.insert(DataToSave,v)

		end
		
	end

DataStore:SetAsync(Player.UserId.."-Queue",DataToSave)

end)

And the error message was a
スクリーンショット (75)

So how do i get playerGui while player removing?

You can’t really do that cause PlayerGui is removed when the player leaves.

you need to save things in a database not a gui.

You could save the content you want to save to a table/variable every 30 seconds or so and then just datastore the most recent save.

(Only save the most recent one when they leave, of course.)

Yeah, but that’s a GUI in PlayerGUI. The GUI will be destroyed as well and the variable/ table key would return as nil.

I think the best solution to this is to either place the GUI somewhere else than PlayerGui or code something that detects changes inside the GUI so you could clone the GUI and then apply the changes to the clone. Then save the clone.

I use this module for my plot building game and it’s just perfect. No performance loss either and it saves a lot of time.

Thanks I made other tirgger to save

Instead of saving a clone like @BandQueenForever said, just cache the GUI in a variable as so:

local cachedUI = Player:WaitForChild("PlayerGui")

The variable will return nil as it’s removed dude.

1 Like

It won’t, please do research before posting.

Alr im dumb i just tested it I never knew about that thank you my master

yo what but its actually so realistic tho ok im so dumb

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.