My points or values will not save what did I do wrong?
Datastore Script(in ServerScriptService)
local DS = game:GetService("DataStoreService"):GetDataStore("Levelz")
local StatFile = game:GetService("ServerStorage"):WaitForChild("StatFile")
game.Players.PlayerAdded:connect(function(player)
local Key = "Player-"..player.userId
local playerfolder = Instance.new("Folder", StatFile)
playerfolder.Name = player.Name
local strength = Instance.new("IntValue", playerfolder)
strength.Name = "Strength"
local defense = Instance.new("IntValue",playerfolder)
defense.Name = "Defense"
local sword = Instance.new("IntValue", playerfolder)
sword.Name = "Sword"
local slevel = Instance.new("IntValue", playerfolder)
slevel.Name = "SLevel"
local health = Instance.new("IntValue", playerfolder)
health.Name = "Health"
if DS:GetAsync(Key) then
defense.Value = DS:GetAsync(Key)
strength.Value = DS:GetAsync(Key)
sword.Value = DS:GetAsync(Key)
health.Value = DS:GetAsync(Key)
slevel.Value = DS:GetAsync(Key)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local Key = "Player-"..player.userId
local AllStats = game.ServerStorage.StatFile[player.Name]:GetChildren()
for i = 1, #AllStats do
DS:SetAsync(Key,AllStats[i].Value, AllStats[i].Name)
end
end)
