Hey all, working on simple rpg system here and am having trouble getting it to work. the basic idea is that you kill enemies to level up which increases your health and, ideally, running and jumping speed by a bit and this is all saved via datastore. this is my server side code:

local DataStore2 = require(1936396537)

DataStore2.Combine("MasterKey", "Level", "XP", "Health")

local defaultLevel = 1 local defaultXP = 0 local defaultHealth = 100

local xpToLevelUp = function(level) return 100 + level * 5 end

game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player); leaderstats.Name = "leaderstats"

local levelValue = Instance.new("IntValue", leaderstats); levelValue.Name = "Level"
local xpValue = Instance.new("IntValue", leaderstats); xpValue.Name = "XP"
 

local levelStore = DataStore2("Level", player)
local xpStore = Datastore2("XP", player)
local healthStore = Datastore2("Health", player)

local funtion updateLevel(level)
	player.leaderstats.Level.Value = level
end

local function updateXP(xp) if xp >= xpToLevelUp(levelStore:Get(defaultLevel)) then xpStore:Increment(xpToLevelUp(levelStore:Get(defaultLevel)) * -1) levelStore:Increment(1) healthStore:Increment(50) else player.leaderstats.XP.Value = xp end end

updateLevel(levelStore:Get(defaultLevel)) updateXP(xpStore:Get(defaultXP))

levelStore:OnUpdate(updateLevel) xpStore:OnUpdate(updateXP) end)

I also add this code to enemies to give xp:

local humanoid = script.Parent:WaitForChild("Humanoid") humanoid.Died:Connect(function() local xpStore = DataStore2("XP", player)

xpStore:Increment(5)

end)

I can't tell if my xp bar isn't working due to my not gaining xp or because i'm coding it wrong, but probably both since i cant get the health one to work either. but i figure one step at a time.

thanks in advance for any help.