-
What do you want to achieve?
I just want the folders to be created, like the code to work. -
What is the issue?
The playeradded function doesnt seem to work at all.
-- DATASTORE --
local DataStore2 = require(1936396537)
DataStore2.Combine("MasterK", "Level", "XP")
local defaultLevel = 1
local defaultXP = 0
local xpToLevelUp = function(level)
return 100 + level * 35
end
game:GetService("Players").PlayerAdded:Connect(function(player)
print("lol")
-- misc --
local misc = Instance.new("Folder", player)
misc.Name = "Misc"
local xpValue = Instance.new("IntValue", misc)
xpValue.Name = "XP"
local xpRequired = Instance.new("IntValue", misc)
xpRequired.Name = "XPRequired"
-- leaderstats --
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local levelValue = Instance.new("IntValue", leaderstats)
levelValue.Name = "Level"
-- get datastores --
local levelStore = DataStore2("Level", player)
local xpStore = DataStore2("XP", player)
-- functions when level and xp are updated --
local function updateLevel(level)
player:WaitForChild("leaderstats"):WaitForChild("Level").Value = level
player:WaitForChild("Misc"):WaitForChild("XPRequired").Value = 100 + level * 35
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:WaitForChild("Misc"):WaitForChild("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)
Maybe I have some spelling mistake somewhere, any help appreciated!