Script isnt finding updated value

I am making a leveling system, and I have a intvalue under the player that has experience. But even if i continually print it, it will say the value of experience is 0 even though i changed it to 1. Here is my script:

game.Players.PlayerAdded:Connect(function(player)
	local levelInfo = Instance.new("Folder")
	levelInfo.Name = "LevelsInfo"
	levelInfo.Parent = player

	local level = Instance.new ("IntValue")
	level.Name = "Level"
	level.Value = 1
	level.Parent = levelInfo

	local exp = Instance.new ("IntValue")
	exp.Name = "Experience"
	exp.Value = 0
	exp.Parent = levelInfo

	local xpNeeded =50* level.Value

	exp.Changed:Connect(function(newExp)-- this always thinks it is 0 even though i change it
		if newExp >= xpNeeded then
			level.Value += 1
			exp.Value -= xpNeeded
			xpNeeded = 50*level.Value
		end
	end)
end)

Instead of using newExp, Use exp.Value. Another thing i recommend you doing is changing the exp.Changed Event to exp:GetPropertyChangedSignal("Value").

Try flipping the symbols here: instead of level.Value += 1
Do level.Value = level.Value +1

1 Like

Thats not what isnt working, it is that it doesnt detect a change if the value changes.

That won’t make a difference, neither will the GetPropertyChangedSignal suggested by @MeCrunchAstroX. However using exp.Value is better than newExp

I will try that, what are the differences between .changed and getpropertychagned signal?

edit: never mind, it is just that it doesnt even know that the value is changed. For example:
if I put I loop in it that prints the value of exp every second, it should print 0 until i change it, but once i change it it still prints 0

2 important things, are you changing the value on the server, and if you are, add a print statement before the if statement in the changed function

P.S There is no visible differences between .Changed and GetPropertyChangedSignal

GetPropertyChangedSignal will only fire once the certain Value is changed. Meanwhile the Changed Event will fire whenever any property of the Instance gets modified.

However when working with Values (such as IntValues ect.) .Changed fires when the value of that Instance gets changed.

I am changing the value on the server

It just doesnt think it changed for some reason, even though i changed it. For example:
if I put I loop in it that prints the value of exp every second, it should print 0 until i change it, but once i change it it still prints 0

Are you sure you are changing the value from the server?
Make sure you are since client updates aren’t replicated to server

yes, I am using a server script to change the value for the other script to pick up

hmmm
try doing this

exp:GetPropertyChangedSignal("Value"):Connect(function()
	if exp.Value>= xpNeeded then
		level.Value += 1
		exp.Value -= xpNeeded
		xpNeeded = 50*level.Value
	end
end)