Yeah need help fixing this error
-- DATASTORE --
local DataStore2 = require(1936396537)
DataStore2.Combine("MasterKey", "Level", "XP", "Coins")
local defaultLevel = 1
local defaultXP = 0
local xpToLevelUp = function(level)
return 100 + level * 5
end
game.Players.PlayerAdded:Connect(function(player)
-- leaderstats --
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"
-- get datastores --
local levelStore = DataStore2("Level", player)
local xpStore = DataStore2("XP", player)
--local coinsStore = DataStore2("Coins", player)
-- functions when level and xp are updated --
local function 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) -- level up
else
player.leaderstats.XP.Value = xp
end
end
-- call functions right away one time
updateLevel((levelStore:Get(defaultLevel)))
updateXP(xpStore:Get(defaultXP))
-- call functions again on updates
levelStore:OnUpdate(updateLevel())
xpStore:OnUpdate(updateXP())
end)
if xp >= xpToLevelUp(levelStore:Get(defaultLevel)) then
^this line causes that error