Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

FE DataStore Script Isn't Saving?

So, im making a Loading Menu game where I need a Player's Data to load which all the Values are inside a Folder called 'Inventory', which is located in the Player.

local DSService = game:GetService('DataStoreService'):GetDataStore('PlayerData')

game.Players.PlayerAdded:connect(function(plr)
 -- Define variables
 local uniquekey = 'id-'..plr.userId
 local datafolder = script.Inventory
 local j = datafolder:Clone()
 j.Name = ''..plr.userId..''
 local cashvalue =  Instance.new('IntValue',j)
 local shirtvalue =  Instance.new('NumberValue',j)
 local pantsvalue =  Instance.new('NumberValue',j)
 local haircolorvalue =  Instance.new('BrickColorValue',j)
 local hairvalue =  Instance.new('StringValue',j)
 cashvalue.Name = 'Cash'
 shirtvalue.Name = 'ShirtEquipped'
 pantsvalue.Name = 'PantsEquipped'
 haircolorvalue.Name = 'HairColor'
 hairvalue.Name = 'HairEquipped'
 cashvalue.Value = 50000
 shirtvalue.Value = 523095212
 pantsvalue.Value = 585084183
 haircolorvalue.Value = BrickColor.new('Really black')
 hairvalue.Value = 'TreckyHair'
 j.Parent = plr
 
 -- GetAsync
 local GetSaved = DSService:GetAsync(uniquekey)
 if GetSaved then
  cashvalue.Value = GetSaved[1]
	shirtvalue.Value = GetSaved[2]
	pantsvalue.Value = GetSaved[3]
	haircolorvalue.Value = GetSaved[4]
	hairvalue.Value = GetSaved[5]
 else
  local NumbersForSaving = {cashvalue.Value, shirtvalue.Value, pantsvalue.Value, haircolorvalue.Value, hairvalue.Value}
  DSService:SetAsync(uniquekey, NumbersForSaving)
 end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local SaveTable = {plr[''..plr.userId..''].Cash.Value, plr[''..plr.userId..''].ShirtEquipped.Value, plr[''..plr.userId..''].PantsEquipped.Value, plr[''..plr.userId..''].HairColor.Value, plr[''..plr.userId..''].HairEquipped.Value}
 DSService:SetAsync(uniquekey, SaveTable) 
 
 
end)

The Problem is that it doesn't save.

1 answer

Assuming your testing this in Studio; first off you should ensure that you have this enabled in your place's settings Enable Studio Access to API Services. And you may want to try using game:BindToClose() because when you press Stop in studio it doesn't always allow enough time for game.Players.PlayerRemoving(). Here's a quick example of what this should look like.

game:BindToClose(function()
	for _, plr in pairs(game.Players:GetChildren()) do
		local uniquekey = 'id-'..plr.userId
		local SaveTable = {plr[''..plr.userId..''].Cash.Value, 		plr[''..plr.userId..''].ShirtEquipped.Value, plr[''..plr.userId..''].PantsEquipped.Value, 		plr[''..plr.userId..''].HairColor.Value, plr[''..plr.userId..''].HairEquipped.Value}
		DSService:SetAsync(uniquekey, SaveTable)
	end
end)

1 comment

0

I was testing in Studio, and in-game and this isnt saving still and I don't know why :/ and yes my API Services are on.

This discussion is preserved as it was. New answers, comments, and votes are closed.