You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Recording value of value
What is the issue? Include screenshots / videos if possible!
value value is not saved without any error
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
no
local datastoreS = game:GetService("DataStoreService")
local store = datastoreS:GetDataStore("StandId")
game:GetService("Players").PlayerAdded:Connect(function(plr)
local fold = Instance.new("Folder",plr)
fold.Name = "Stand"
local first = store:GetAsync(plr.UserId) or 0
local val = Instance.new("IntValue",fold)
val.Name = "Stand"
val.Value = first
print(plr.Stand.Stand.Value)
end)
game.Players.PlayerRemoving:Connect(function(plr)
store:SetAsync(plr.UserId, plr.Stand.Stand.Value)
print(plr.Stand.Stand.Value)
end)
First of all I see many things that could cause this.
You didn’t wrap the async functions in a pcall.
Use game:BindToClose() to save the players data when the server is shutting down
Studio often closes too quickly for the datastores to save so if you don’t wanna keep it open longer manually when you close the studio session, try it out in the real game. If you do want to, look at 2. and save each player alongside each other with a coroutine so that the time is sufficient enough to save each player.
local DSS = game:GetService("DataStoreService")
local valueStore = DSS:GetDataStore("valueStore")
game.Players.PlayerAdded:Connect(function(plr)
local fold = Instance.new("Folder",plr)
fold.Name = "Stand"
local val = Instanc.new("IntValue",fold)
val.Name = "Stand"
local first -- adding a nil value which will be our value
local success, errorMessage = pcall(function()
first = valueStore:GetAsync(plr.UserId)
end
if success then
val.Value = first
end
if errorMessage then
warn(errorMessage) -- Gives the error then
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local sucess, errMessage = pcall(function()
valueStore:SetAsync(plr.UserId,plr.Stand.Value)
end
if sucess then
print("Data has been saved!")
end
if errMessage then
warn(errMessage)
end
end
local datastoreS = game:GetService("DataStoreService")
local store = datastoreS:GetDataStore("StandId")
game:GetService("Players").PlayerAdded:Connect(function(plr)
local fold = Instance.new("Folder",plr)
fold.Name = "Stand"
local first = store:GetAsync(plr.UserId) or 0
local val = Instance.new("IntValue",fold)
val.Name = "Stand"
val.Value = first
print(plr.Stand.Stand.Value)
end)
game.Players.PlayerRemoving:Connect(function(plr)
pcall(function()
store:SetAsync(plr.UserId, plr.Stand.Stand.Value)
end)
print(plr.Stand.Stand.Value)
end)
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
pcall(function()
store:SetAsync(v.UserId, v.Stand.Stand.Value)
end)
end
end)