Exp, level system help

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!

2 Likes

Man thank you for the script it’s really useful! For people who wants create a game where you must get EXP to level up.

Ok! But I need help, so if you know, it would be good.

You could use the .Changed event

EXP.Changed:Connect(function(newValue --Optional)
     -- Code here
end)

Sorry for late reply, but not working for me. I think it should work only with some loop. (I don’t want to use them)