I'm very new to data stores and all I'm trying to do is save the value of a bool value. It does not work for some reason though, and I can't figure out why.
Here is my code:
local dss = game:GetService("DataStoreService")
local playerData = dss:GetDataStore("DataStore")
local function onPlayerJoin(player)
local onMenu = Instance.new("BoolValue")
onMenu.Name = ("onMenu")
onMenu.Parent = player
local userId = tostring(player.UserId)
local data = playerData:GetAsync(userId)
if data then
onMenu.Value = data
else
onMenu.Value = true
end
end
local function onPlayerExit(player)
local success, err = pcall(function()
local userId = tostring(player.UserId)
playerData:SetAsync(userId, player.onMenu.Value)
end)
if not success then
warn("couldn't save data")
else
print("success")
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)

2 comments
Are you testing this in studio?
yes