I made a item saving system for my game a few days ago, ive recently noticed this bug where items dont save if you are ingame, but they somehow save inside studio?
Code
local function saveData(player)
local tableToSave = {
player.Data.Strength.Value;
player.Data.Speed.Value,
player.Data.InCombat.Value,
player.Data.SkinColor.Value,
player.Data.Strength.Value,
player.Data.New.Value,
player.Data.Lives.Value,
player.Data.Armor.Value,
player.Data.Face.Value,
player.Data.Traits.Value,
player.Data.LastPosition.Value,
player.Data.HairColor.Value,
player.Data.Hair.Value,
player.Data.Weapon.Value,
player.Data.WeaponXp.Value,
}
for i,v in pairs(player.Backpack:GetChildren()) do
table.insert(tableToSave, v.Name)
end
local success, err = pcall(function()
datastore:SetAsync(player.UserId, tableToSave)
end)
if success then
else
warn(err)
end
end
PlayerRemoving
game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
saveData(player)
end)
if success then
warn(player.Name.."'s Data has been saved.. ID"..player.userId)
else
warn(player.Name.."'s Data has not been saved!.. ID"..player.userId)
end
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
local success, err = pcall(function()
saveData(player)
end)
if success then
warn(player.Name.."'s Data has been saved.. ID"..player.userId)
else
warn(player.Name.."'s Data has not been saved!.. ID"..player.userId)
warn(err)
end
end
end)
Load Tools
for i,v in pairs(data) do
if Items:FindFirstChild(v) and InCombat.Value == false then
Items[v]:Clone().Parent = player.Backpack
end
end
i dont know why this happens, if somebody knows how to fix this, please tell me as this is making me pretty desperate.
Edit: now it doesnt want to save in studio either
Edit #2: i worked out a temporal fix that might cause data issues, im still waiting for someone to give me a possible solution
You want to save string.
DSS(DataStoreService) Is intended to save string.
I will break it down so everyone can fully understand what you can really do with DSS.
It can be used for much more than just player data.
-- This is the DSS service that allows access to the stores.
local DSS = game:GetService("DataStoreService")
-- Gets The Store With The String 'Player Experience
-- This Can Be Any String And The String Can Even Be Created
local XP = DSS:GetDataStore("PlayerExperience")
-- This Will Assign Data To The String, The String Can Be Anything
-- People Often Mistake DSS For Saving Player Data
-- However It Saves To A String Not The Player
XP:SetAsync("Player_1234", 50)
The Key To Remember Is that DataStores can save string or integers upto 250,000 Kb. I find it easier to use them when I think of DSS as a sort of folder system.
StoreString.IdentifyingString --> Access To The Saved Value
Many misunderstand the key fact that you can make your own strings and names and even store the names of stores in other stores. You can make an advanced network quickly once you understand this key fact and realise what you have overlooked.
The DSS limits can be bypassed by creating multiple save values. I’ve done this by using one store to store the name of another. Then every value in that second store has its identifying string set to a number. This means I can literally save lists and endless data that can be retried using for loops.
There’s also another rule towards the DataStoreService on the engine side, the value has to a string, or something that can be stringified and that it can be strinified to a UTF-8 character.
With this, even though it looks like I am going to set this key name test as the integer 1, because it’s url encoded, it will become a string.
POST https://gamepersistence.roblox.com/persistence/set?key=test&type=standard&scope=global&target=test&valueLength=3
Accept: application/json
Cookie: .ROBLOSECURITY={{cookie}}
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Connection: close
Roblox-Place-Id: {{placeId}}
Content-Type: application/x-www-form-urlencoded
&value=123