My DataStore script won't save or maybe won't load players data. I have a button in game that raises the values of GoldRubyC and CollectionValue
local datastore = game:GetService("DataStoreService"):GetDataStore("tablohazerjia1")
game.Players.PlayerAdded:connect(function(player)
local PlayerProfile = Instance.new("Folder")
PlayerProfile.Name = "PlayerProfile"
PlayerProfile.Parent = player
-------------------- [Collected Treasure Verified]-
local TreasuresCollected = Instance.new("IntValue")
TreasuresCollected.Name = "TreasuresCollected"
TreasuresCollected.Parent = PlayerProfile
---------------------------------------------------
---------------------[Treasures]--------------------
local GoldRubyC = Instance.new("IntValue")
GoldRubyC.Name = "GoldRubyC"
GoldRubyC.Parent = PlayerProfile.TreasuresCollected
---------------------------------------------------
---------------------[Collection Value]------------
local CollectionValue = Instance.new("IntValue")
CollectionValue.Name = "CollectionValue"
CollectionValue.Parent = PlayerProfile
--------------------------------------------------
local key = "user_" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
TreasuresCollected.Value = storeditems[1]
GoldRubyC.Value = storeditems[2]
CollectionValue.Value = storeditems[3]
else
local items = {TreasuresCollected.Value, GoldRubyC.Value, CollectionValue.Value}
datastore:SetAsync(key, items)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {player.PlayerProfile.TreasuresCollected.Value, player.PlayerProfile.TreasuresCollected.GoldRubyC.Value, player.PlayerProfile.CollectionValue.Value}
local key = "user_" ..player.userId
datastore:SetAsync(key, items)
end)

1 comment
are you changing the values locally or server side?