I am currently working on Level System for my game. But the script is not perfect. I have the mechanic done, but because i am new to scripting, I don’t know how to use RemoteEvents, or GetPropertyChangedSignal. So, I need to call the function if player’s EXP changes (or player pick up coin but i think exp change is better). Code is here:
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
local event = game.ReplicatedStorage.Remotes.UpdateExp
local leaderstats = player:WaitForChild("leaderstats")
local hiddenleaderstats = player.hiddenleaderstats
local EXP = hiddenleaderstats.EXP
local levels = Instance.new("IntValue", leaderstats)
levels.Name = "Levels"
end)
local function Update (player)
local leaderstats2 = player:WaitForChild("leaderstats")
if not leaderstats2 then return end
local hiddenleaderstats2 = player:WaitForChild("leaderstats")
if not hiddenleaderstats2 then return end
local EXP = hiddenleaderstats2:WaitForChild("EXP")
if not EXP then return end
local levels2 = leaderstats2.Levels
if levels2.Value == 0 then
levels2.Value = 1
end
local expneeded = levels2.Value * 2
if EXP.Value >= expneeded then
levels2.Value = levels2.Value + 1
EXP.Value = EXP.Value - expneeded
end
end
Thanks!