This datastore makes any NEW value I insert and puts it to 0.
Also, whenever I CHANGE the value it keeps the saved one, instead of changing it… Why?
local DataStore = game:GetService("DataStoreService"):GetDataStore("MyDataStore")
game.Players.PlayerAdded:Connect(function(player)
local key = "key-"..player.userId
local folder = Instance.new("Folder", player)
folder.Name = "leaderstats"
local StaminaMax = Instance.new("NumberValue", folder)
StaminaMax.Name = "StaminaMax"
StaminaMax.Value = 100
local StrengthMax = Instance.new("NumberValue", folder)
StrengthMax.Name = "StrengthMax"
StrengthMax.Value = 100
local StaminaAmount = Instance.new("NumberValue", StaminaMax)
StaminaAmount.Name = 'StaminaAmount'
StaminaAmount.Value = 100
local StrengthAmount = Instance.new("NumberValue", StrengthMax)
StrengthAmount.Name = 'StrengthAmount'
StrengthAmount.Value = 1
local Yen = Instance.new("NumberValue", folder)
Yen.Name = "Yen"
Yen.Value = 100
local walkSpeed = Instance.new('NumberValue', folder)
walkSpeed.Name = "Walkspeed"
walkSpeed.Value = 16
---//Base Stats\\---
local baseDamage = Instance.new("NumberValue", player)
baseDamage.Name = 'BaseDamage'
baseDamage.Value = 5
local damage = Instance.new("NumberValue", player)
damage.Name = 'Damage'
damage.Value = baseDamage.Value * StrengthAmount.Value
---//Base Stats\\---
local save = DataStore:GetAsync(key)
if save then
StaminaMax.Value = save[1]
StrengthMax.Value = save[2]
Yen.Value = save[3]
StaminaAmount.Value = save[4]
StrengthAmount.Value = save[5]
walkSpeed.Value = save[6]
else
local load = {StaminaMax.Value, StrengthMax.Value, Yen.Value, StaminaAmount.Value, StrengthAmount.Value, walkSpeed.Value}
DataStore:SetAsync(key,load)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = "key-"..player.userId
local load = {player.leaderstats:FindFirstChild("StaminaMax").Value, player.leaderstats:FindFirstChild('StrengthMax').Value,
player.leaderstats:FindFirstChild("Yen").Value, player.leaderstats.StaminaMax:FindFirstChild('StaminaAmount').Value,
player.leaderstats.StrengthMax:FindFirstChild('StrengthAmount').Value, player.leaderstats:FindFirstChild('Walkspeed').Value}
DataStore:SetAsync(key,load)
end)