Why is .Changed not working?

I am currently trying to display a notification on screen whenever a Stat value is changed, although I am having problems doing so.

game.Players.LocalPlayer.Stats.NPC.Changed:Connect(function()
	print("Changed")
	local tl = Instance.new("TextLabel")
	tl.Parent = Player.PlayerGui.NOTIFICATIONBOX.Frame
	tl.BackgroundTransparency = 1
	tl.TextColor3 = Color3.new(1, 1, 1)
	tl.Size = UDim2.new(1,0,0.245,0)
	tl.TextScaled = true
	tl.Font = "Ubuntu"
	tl.Text = "Succesfully served customer (+1)"

I am not getting any errors when the NPC value is changed and nothing is being printed, I have also already tried:

game.Players.LocalPlayer.Stats.NPC.Value.Changed:Connect(function()

Although that is also not working, any ideas?

2 Likes

You need to detect the change of the object itself, not its value.

Try game.Players.LocalPlayer.Stats.Changed:Connect(function() instead.

That is not working for some reason, The folder is Stats and the value is NPC if that helps.

2 Likes

Is this a localscript or a server script?

Oops typo! I meant game.Players.LocalPlayer.Stats.NPC.Changed:Connect(function()! My apologies.

He has already tried doing that.

1 Like

It is a LocalScript


Is there anything before that part of the script?

:laughing: Brainfart, my bad. Been bouncing between threads.

1 Like

Just this:

local Player = game.Players.LocalPlayer

maybe try it like this:

local Player = game:GetService(“Players”).LocalPlayer

local StatsFolder = Player:WaitForChild(“Stats”)

local NPC = StatsFolder.NPC

NPC.Changed:Connect(function()

print(“Changed”)

local tl = Instance.new(“TextLabel”)

tl.Parent = Player.PlayerGui.NOTIFICATIONBOX.Frame

tl.BackgroundTransparency = 1

tl.TextColor3 = Color3.new(1, 1, 1)

tl.Size = UDim2.new(1,0,0.245,0)

tl.TextScaled = true

tl.Font = “Ubuntu”

tl.Text = “Succesfully served customer (+1)”

end)

Are you missing your

end)

Or did you just forget to copy it to the code above?

Here is a formatted version of that code:

1 Like

How is the NPC stat being changed? Maybe whatever is responsible for changing the stat isn’t doing its job.

1 Like

Are you getting errors when you start the game?

It is changing the value, I have the Value open while I’m testing.

1 Like

No, nor did that other code suggested work.

So it is the Value your changing and not the name.

That doesnt make sense, are you sure that is the right place of the value and is it really getting changed?
and do you really get no errors?

1 Like

Yeah I’m trying to get it to send a notification once the value is changed.