Doesn't find Player Gui help please!

So this is my code:

game.Players.PlayerRemoving:Connect(function(Player)
	local Slot1 = Player.PlayerGui.CustomGradient.Frame.MainFrame.GradientSaves.Slot1.Saved.Color
	local Slot2 = Player.PlayerGui.CustomGradient.Frame.MainFrame.GradientSaves.Slot2.Saved.Color
	local Slot3 = Player.PlayerGui.CustomGradient.Frame.MainFrame.GradientSaves.Slot3.Saved.Color
	local Slot4 = Player.PlayerGui.CustomGradient.Frame.MainFrame.GradientSaves.Slot4.Saved.Color
	
	DataStore:SetAsync(Player.UserId, {
		S1 = Slot1,
		S2 = Slot2,
		S3 = Slot3,
		S4 = Slot4
		
	})
	print("DataSaved")
end)

My problem is that it doesn’t find the PlayerGui and I need it so I can save their custom gradients when they leave the game. How do I fix this?

Error:image

3 Likes

can i see the whole startergui parent explorer?

Its big so I could only fit 1 slot inimage

hmmm, try to put WaitForChild.

The issue is you’re trying to grab the PlayerGui while the Player is leaving - meaning the PlayerGui has already been deleted and is unaccessible

A fix for this could be saving the gradients everytime the user finishes editing them.

I did do that just now but it gives me 104 error and can’t save the color of the UIGradient you know how to fix?

Could you not just save the ColorSequence value?

image

I changed it from a dictionary to normal 1 saveimage

still nothing

Your trying to save it after the player is removed, meaning the PlayerGui Is already deleted.