Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago
Edited 1 year ago

(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

Log in to vote
0
Answered by 1 year ago

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)
0
Ty for that. I understand the gist of it now. YeloJeloYT 2 — 1y
Ad

Answer this question