Value changed error

Hey! Sup.


I was trying to do a HealthBar with a particle effect when get damage or heal.
But somehow, i recive a error:

Players.vitorhinode1234.PlayerGui.UI.StaminaAndLife.Heath.HealthBar.Display:16: attempt to index number with 'Changed'

image

and maybe this dont will be the last error.

Can you guys help me?

The script:

local health = game.ReplicatedStorage.health
local player = game.Players.LocalPlayer
local maxHealth = player.Character:WaitForChild("Humanoid").MaxHealth
local Humanoid = player.Character:WaitForChild("Humanoid")
local Detector = game.ReplicatedStorage.health
local HealthValue = Detector.Value

    health.Changed:Connect(function()
	    script.Parent.Size = UDim2.new(health.Value/maxHealth,0,1,0)
	    script.Parent.Parent.TextLabel.Text = health.Value..' / '..maxHealth
	
	Detector.Value.Changed:Connect(function(new)
		if HealthValue < new then
			script.Parent.Parent.Heal.Enabled=true
			wait(1)
			script.Parent.Parent.Heal.Enabled=false
			
		else
			script.Parent.Parent.Blood.Enabled=true
			wait(1)
			script.Parent.Parent.Blood.Enabled=false
		
		end
		HealthValue = new
	end)
end)

script.Parent.Size = UDim2.new(health.Value/maxHealth,0,1,0)
script.Parent.Parent.TextLabel.Text = health.Value..' / '..maxHealth

Thank you <3
Also, i’m using a module for make the particles work in the GUI.

.changed is a property of an object and not of a property. You are trying to listen for .changed on the Detector.Value when it should just be Detector.Changed.

2 Likes

yes removed the error, but aways dont working.