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.