.Changed event not firing

I have a function in my leaderstats script that says when the exp is changed it should print changed but it does not.

Code:

Exp.Changed:Connect(function()
		print("Changed")
	end)

Full Code:

game.Players.PlayerAdded:Connect(function(player)
	game.Lighting.Blur.Enabled = true
	
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local values = Instance.new("Folder", player)
	values.Name = "Values"

	local gold = Instance.new("IntValue", leaderstats)
	gold.Name = "Gold"
	
	local mana = Instance.new("IntValue", values)
	mana.Name = "Mana"
	mana.Value = 50
	
	local maxMana = Instance.new("IntValue", values)
	maxMana.Name = "MaxMana"
	maxMana.Value = 50
	
	local Level = Instance.new("NumberValue",leaderstats)
	Level.Name = "Level"
	Level.Value = 1

	local Exp = Instance.new("NumberValue",values)
	Exp.Name = "Exp"
	Exp.Value = 0

	local RequiredExp = Instance.new("NumberValue",values)
	RequiredExp.Name = "RequiredExp"
	RequiredExp.Value = Level.Value*100
	
	local class = Instance.new("StringValue", values)
	class.Name = "Class"
	class.Value = "N/A"
	

	Exp.Changed:Connect(function()
		print("Changed")
	end)

end)
2 Likes

Make sure the value is actually being created (I’m sure it is).

The only other thing I can think of is that the value is not actually changing. Make sure it is changing on the SERVER and not just the client, as your script will not detect changes on the client.

2 Likes

I have spent an hour on this. The script is a server script in server script service controlling the leaderstats but it still does not fire in any other script I have tried

Make sure the value is actually being changed. While testing, you can use the server view option to see from the server’s POV. Let me know your results.

That’s a really bad practice, .Changed does work for NumberValue instances, as you can see here.

local numberValue = Instance.new("NumberValue")

numberValue.Changed:Connect(function(number)
	print(number)
end)

numberValue.Value = math.pi

image

4 Likes

Parent the number value instance after you have created a RBXScriptConnection object from its Changed RBXScriptSignal object.

5 Likes