Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

The "GetAttributeChangedSignal" function is not firing. How do I fix that?

(First post)

The script is just a normal script.

I have a part with an attribute called rockHP. (Which is the parent of this script.)

rock = script.Parent

print("test 1")

rock:GetAttributeChangedSignal("rockHP"):Connect(function()
	print("attribute changed")
	local rockHP = rock:GetAttribute("rockHP")
	print(rockHP)
	if rockHP <= 0 then
		rock:Destroy()
	end
end)

print("test 2")

When I manually change it this script doesn't detect anything.

I've tried to find answers online but I couldn't find any that fit my problem.

1 answer

✓ Accepted answer

ur code works fine, the AttributeChangedSignal just doesnt detect when u manually change it. it only detects when something causes the change for example, look at this code:

local rock = script.Parent

rock.Touched:Connect(function(hit) --simple touched event script that sets the rockHP to 0
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		rock:SetAttribute("rockHP",0)
	end
end)

rock:GetAttributeChangedSignal("rockHP"):Connect(function() --now it detects the change
	print("attribute changed")
	local rockHP = rock:GetAttribute("rockHP")
	print(rockHP)
	if rockHP <= 0 then
		rock:Destroy()
	end
end)

1 comment

0

Ty for that. I understand the gist of it now.

This discussion is preserved as it was. New answers, comments, and votes are closed.