How would I check if a player's leaderstat was changed?

Hello. I am working on a script that gives you a certain item once you get in between a certain XP value. It’s not even running the script. It only runs the script once I spawn it, then it stops. The script is a local script in a GUI under startergui.
Here is the code:

	local clearance = 0
	if plr.leaderstats.XP.Value >= 0 and plr.leaderstats.XP.Value <= 20 then
		clearance = 1
		eventClearance:FireServer(clearance)
		print("Given level 1 clearance to " ..plr.Name)
	elseif plr.leaderstats.XP.Value >= 21 and plr.leaderstats.XP.Value <= 60 then
		clearance = 2
		eventClearance:FireServer(clearance)
		print("Given level 2 clearance to " ..plr.Name)
	elseif plr.leaderstats.XP.Value >= 61 and plr.leaderstats.XP.Value <= 120 then
		clearance = 3
		eventClearance:FireServer(clearance)
		print("Given level 3 clearance to " ..plr.Name)
	elseif plr.leaderstats.XP.Value >= 121 and plr.leaderstats.XP.Value <= 300 then
		clearance = 4
		eventClearance:FireServer(clearance)
		print("Given level 4 clearance to " ..plr.Name)
	elseif plr.leaderstats.XP.Value >= 301 and plr.leaderstats.XP.Value <= 1500 then
		clearance = 5
		eventClearance:FireServer(clearance)
		print("Given level 5 clearance to " ..plr.Name)
	elseif plr.leaderstats.XP.Value >= 1501 and plr.leaderstats.XP.Value <= 5000 then
		clearance = "onmi"
		eventClearance:FireServer(clearance)
		print("Given Omni clearance to " ..plr.Name)
	end
end```
plr.leaderstats.XP.changed:Connect(function()
	-- your code here
end)
1 Like

Wow. I complete forgot to do that, thanks.

plr.leaderstats.XP.Changed:Connect(function(newVal)
	-- your code here
end)

Changed should be capitalised. Also don’t forget that the new value is automatically passed as an argument to any function connected to a “Changed” event so you can define the function to receive a parameter of any name to handle this passed value. By doing that you can use the new value inside the body of the function.

Already solved, but thanks for the answer again.