Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Datestore not saving my value when rejoining?

Asked by
knotam 3
5 years ago
Edited 5 years ago

I have this piece of code, i'm trying to make it save only NOK when the player joins however when I join my value of "NOK" is reset to 0... What am I doing wrong?

Also I have no idea how to get more than one line in a codeblock at a time?

``` CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")

function PlayerEntered(player) repeat wait() until player.Character

local stats = Instance.new("IntValue") stats.Parent = player stats.Name = "leaderstats"

local cash = Instance.new("IntValue") cash.Parent = stats cash.Name = "Wood" cash.Value = 0

local stone = Instance.new("IntValue") stone.Name = "Stone" stone.Parent = stats stone.Value = 0

local NOK = Instance.new("IntValue") NOK.Name = "NOK" NOK.Parent = stats

if CashStore:GetAsync("NOK"..player.Name) ~= nil then NOK.Value = CashStore:GetAsync("NOK"..player.Name)

else NOK.Value = 0 end

NOK.Changed:connect(function(Val) CashStore:SetAsync("NOK"..player.Name, Val)

end) end

game.Players.PlayerAdded:connect(PlayerEntered)

Answer this question