local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("datatest")
game.Players.PlayerAdded:Connect(function(plr)
local Folder = Instance.new("Folder",plr)
Folder.Name = "test"
local BoolValue = Instance.new("BoolValue",Folder)
BoolValue.Name = "BoolValue"
local dataofuser = ds:GetAsync(plr.UserId)
if dataofuser ~= nil then -- anything but nil
print("Found data for " .. plr.Name)
BoolValue.Value = BoolValue.Value
else
print("Replacing no data with new data.")
BoolValue = false
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local datasave = {}
table.insert(datasave, plr:WaitForChild("test"):WaitForChild("BoolValue").Value)
local success,response = pcall(function()
ds:SetAsync(plr.UserId, datasave)
end)
if success then
print("succesfully saved data of " .. plr.Name)
else
warn(response)
end
end)
local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("datatest")
game.Players.PlayerAdded:Connect(function(plr)
local Folder = Instance.new("Folder", plr)
Folder.Name = "test"
local BoolValue = Instance.new("BoolValue", Folder)
BoolValue.Name = "BoolValue"
local dataofuser = ds:GetAsync(plr.UserId)
if dataofuser then
BoolValue.Value = dataofuser[1]
else
print("Replacing no data with new data.")
BoolValue.Value = false
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local datasave = {plr:WaitForChild("test"):WaitForChild("BoolValue").Value}
local success, response = pcall(function()
ds:SetAsync(plr.UserId, datasave)
end)
if success then
print("Successfully saved data of " .. plr.Name)
else
warn(response)
end
end)