Issues with datastore

the data is stored in the players userId and contains the values

1 Like

This is from a free model, but shows how you use tables:

local storeditems = datastore:GetAsync(key)
	if storeditems then
		points.Value = storeditems[1] 
		wins.Value = storeditems[2] 
		noob.Value = storeditems[3]
		survivals.Value = storeditems[4]
		max.Value = storeditems[5]
	else
		local items = {points.Value, wins.Value, noob.Value, survivals.Value, max.Value} 
		datastore:SetAsync(key, items)
	end

(This assumes that you already created int (or another) value’s with variable names in items.

Saving:

local items = {player.stats.Coins.Value, player.stats.Level.Value, player.stats.EXP.Value, player.leaderstats.Survivals.Value, player.stats.MaxEXP.Value} 
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
1 Like
	local BlueSize = AllDataStores:GetAsync(Player.UserId)[1] or 0.017
	local CurrentExp = AllDataStores:GetAsync(Player.UserId)[2] or 0
	local MaxExp = AllDataStores:GetAsync(Player.UserId)[3] or 120

Look.
If the GetAsync from the player is nil, it will put instead the value after it - 0.017, 0, 120…

lets do this

local BlueSize

pcall(function()
      BlueSize = AllDataStores:GetAsync("String"..Player.UserId)[1] or 0.017
end)

if BlueSize then
     -- do something

else

       -- oops they do not have saved data give them a default value!

end
1 Like

adding to my code

The DataStore has something saved so the value should be like, there maybe something saved so the value in the datastore is the saved idk value then load it in

Idk.Value = BlueSize
1 Like

I tried that but it’s still not solving my issue, it just keeps setting the value again to 0.017…

what is 0.017? a default value or a userID if a value remove it

It’s a default value. What to do with it?

as i said on my other 2 replies the if statement with the else make the value there not in the ds

That’s what I did… If the GetAsync is nil, it will set to 0.017

local BlueSize

pcall(function()
      BlueSize = AllDataStores:GetAsync("String"..Player.UserId)[1] or 0.017
end)

if BlueSize then
     -- do something
    BlueSize1.Value = BlueSize
else

       -- oops they do not have saved data give them a default value!
         BlueSize1.Value = 100 -- change 100 to anything if possible
end

is this what u did?

1 Like

Yes I did that, and no matter what I tried it’s not working.
I just want to pass a single variable.
Here is my script now:

game.Players.PlayerRemoving:Connect(function(Player)
	local Key = "user-"..Player.UserId
	local TransferValues = Player.PlayerGui:WaitForChild("EXPBarUP"):WaitForChild("CurrentExp").Value
	AllDataStores:SetAsync(Key, TransferValues)
end)





game.Players.PlayerAdded:Connect(function(Player)
	local Key = "user-"..Player.UserId
	local SyncFromData = AllDataStores:GetAsync(Key)
	print(SyncFromData)
	Player.PlayerGui:WaitForChild("EXPBarUP"):WaitForChild("CurrentExp").Value = SyncFromData
end)

And of course it is still not working.

Can I See What Your StarterGui Looks Like?

1 Like

try putting the player removing event below the player added or else it wont work

1 Like

I tried, it’s still not working…

if you use set async then try this

Data:SetAsync("String"..plr.UserId)

thats because the value will remain inside the data store and it wont be nil

1 Like

i kinda get your error literally

1 Like

I have another issue now…

game.Players.PlayerRemoving:Connect(function(Player)
	local CurrentExp = Player.PlayerGui.ExpBarUp.CurrentExp
	local BlueSize = Player.PlayerGui.EXPBarUP.Frame.Size.X.Scale
	local TransferValues = {CurrentExp.Value, BlueSize}
	
	print(TransferValues[1])
	print(TransferValues[2])
	
	AllDataStores:SetAsync(Player.UserId, TransferValues)
end)

This is my player removing script.
But it always gives the error:
[ PlayerGui is not a valid member of Player]
How comes the PlayerGui is not a member of the Player?

:WaitForChild() or lower case the p letter

2 Likes

If I use WaitForChild() it just says it’s infinity, and it’s not lower case…