I took a youtuber’s script for a level system and I don’t really understand how to fix the errors, please help me
local level = 1
local exp = 0
local axp = 20
local InStudio = game:GetService(“RunService”):IsStudio()
if not InStudio then
level = game:GetService("DataStoreService"):GetDataStore("Levels",1)
exp = game:GetService("DataStoreService"):GetDataStore("EXP",1)
axp = game:GetService("DataStoreService"):GetDataStore("AXP",1)
end
function savedata(dataname, playerid, value)
dataname:SetAsync(playerid, value)
end
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder")
leader.Name = "leaderstats"
leader.Parent = player
local levelz = Instance.new("IntValue")
levelz.Name = "Level"
local xpz = Instance.new("NumberValue")
xpz.Name = "Exp"
local xpn = Instance.new("IntValue")
xpn.Name = "ExpNeeded"
if not InStudio then
xpn.Value = axp:GetAsync(tostring(player.userId)) or 20
xpz.Value = exp:GetAsync(tostring(player.userId)) or 0
levelz.Value = level:GetAsync(tostring(player.userId)) or 1
else
xpn.Value = axp
xpz.Value = exp
levelz.Value = level
end
levelz.Parent = leader
xpz.Parent = leader
xpn.Parent = leader
xpz.Changed:connect(function()
if player.leaderstats:WaitForChild("Exp").Value >= player.leaderstats:WaitForChild("ExpNeeded").Value then
levelz.Value = levelz.Value + 1
xpn.Value = math.floor(xpn.Value * 2)
xpz.Value = 0
savedata(level, player.userId, levelz.Value)
savedata(exp, player.userId, xpz.Value)
savedata(axp, player.userId, xpn.Value)
else
end
end)
end)
game.Players.PlayerRemoving:connect(function(player)
savedata(level, player.userId, player.leaderstats.Level.Value)
savedata(exp, player.userId, player.leaderstats.Exp.Value)
savedata(axp, player.userId, player.leaderstats.ExpNeeded.Value)
end)