I'm working on a game that involves DataStore. My code works in studio, and the stats save even when I join an actual server but won't update further once in game. (the moves wont add exp when they should)
local exp = game:GetService("DataStoreService"):GetDataStore("exp")
local lvl = game:GetService("DataStoreService"):GetDataStore("level")
function updateExp(value)
value = game.StarterGui.IntValues.exp.Value
end
function updateLevel(value)
value = game.StarterGui.IntValues.level.Value
end
game.Players.PlayerAdded:connect(function(Player)
local PlayerKey = "user_" .. Player.userId
local leaderstats = Instance.new("IntValue", Player)
leaderstats.Name = "leaderstats"
local experience = Instance.new("IntValue", leaderstats)
experience.Name = "Experience Points"
experience.Value = exp:GetAsync(PlayerKey) or 0
local level = Instance.new("IntValue", leaderstats)
level.Name = "Level"
level.Value = lvl:GetAsync(PlayerKey) or 0
game.StarterGui.IntValues.exp.Value = experience.Value
game.StarterGui.IntValues.level.Value = level.Value
local plr = game.Players.LocalPlayer
plr.Character.Humanoid.MaxHealth = game.StarterGui.IntValues.level.Value*10+100
plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth
spawn(function() while wait() do
if plr.Character.Humanoid.Health < plr.Character.Humanoid.MaxHealth then
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + .01
end
end end)
spawn(function()
game.StarterGui.IntValues.exp:GetPropertyChangedSignal("Value"):connect(function()
exp:UpdateAsync(PlayerKey, updateExp)
experience.Value = game.StarterGui.IntValues.exp.Value
lvl:UpdateAsync(PlayerKey, updateLevel)
level.Value = game.StarterGui.IntValues.level.Value
wait()
end)
end)
end)
