My gui data store doesn't work properly

So, I’ve been trying my best to make a gui data store with bool values. And it kinda works but everytime I leave the game, the output prints, guidata is not a valid member of “Player.USERNAME”

Here’s the code I used:

local DataStoreService = game:GetService("DataStoreService")

local DataStoreName = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local guidata = Instance.new("BoolValue")
	guidata.Name = "GUI"
	guidata.Parent = player
	
	local data
	local success, errormessage = pcall(function()
		data = DataStoreName:GetAsync(player.UserId.."-XP")
		guidata.Value = data
	end)
	
	if success then
		print("Data Loaded")
	else
		print("Error")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall (function()
		DataStoreName:SetAsync(player.UserId.."-XP",player.guidata.Value)
	end)	
	
	if success then
		print("Data has been saved")
	else
		print("Error")
		warn(errormessage)
	end
end)

Any help is appreciated.

It is because the name of guidata isn’t “guidata”, it’s “GUI.” Make sure when you reference a specific object, you refer to it by the correct name.

Ok, so what’s happening is, when I press the button to make the value false or true, it doesn’t save that property. Here is the code I used for the button:

local guidata = game.Players.LocalPlayer.GUI

script.Parent.MouseButton1Click:Connect(function()

guidata.Value = true

end)

And here’s what I’m using to check if the value is set to false:

while true do
	wait(1)
	if game.Players.LocalPlayer.GUI.Value == false then
		script.Parent.Frame.Visible = false
	end
end