local dss = game:GetService("DataStoreService")
local playerds = dss:GetDataStore("playerds")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats
local playerId = player.UserId
local data
local success, errormessage = pcall(function()
data = playerds:GetAsync(playerId)
end)
if success then
Level.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerId = player.UserId
local success, errormessage = pcall(function()
local data = player.leaderstats.Level.Value
playerds:SetAsync(playerId, data)
end)
if success then
print("it worked :D")
else
print("oops")
warn(errormessage)
end
end)
#data store not working, 0 errors
15 messages · Page 1 of 1 (latest)
Did you test the data-store in-game?
Can Studio access DataStore?
Go to Game Settings -> Security -> Enable Studio Access to API Services and make sure thats on
it wasnt on and i enabled it and it still is not working
yeahhh
Convert the function you connected to Players.PlayerRemoving to a named function, then add the following code:
Players.PlayerRemoving:Connect(function(...)
-- ...
end)
-- To:
local function onPlayerRemoving(...)
-- ...
end
Then:
-- Change to
Players.PlayerRemoving:Connect(onPlayerRemoving)
game:BindToClose(function()
for _, player in Players:GetPlayers() do
task.spawn(onPlayerRemoving, player)
end
end)
The server shuts down when the last client disconnects, and that is always the case in a solo studio session
ok but just a question, what does for**_** mean and what is the difference between it and i second question is what does task.spawn mean
is it just like spawn()???
"i" has zero functional significance—it's just a "loop" variable
Like any variable, you can choose any valid name
"_" is among those valid names. "_" is used to name variables whose existence is necessary to reach positional values, but will will never be used
Why name a variable something if it will never be called upon? "_" acts a blank space, so it's optimal over a random character