GetAttributeChangedSignal doesn't work in client

It does work. The problem was that I forgot to connect the event:

--Bad
instance:GetAttributeChangedSignal("attribute", function()
end);

--Good
instance:GetAttributeChangedSignal("attribute"):Connect(function()
end);

Sadly Roblox doesn’t error yet with functions like GetAttributeChangedSignal, so I never knew I was doing it wrong.

Original Problem

I can’t believe this is not a feature. I don’t know if I am doing anything wrong but I am making a Client Handler that requires this attribute detection. After seeing that it wasn’t working I decided to test every part of the code apart and I found out a client can’t detect when the server makes a change:

--Server
local myPart = Instance.new("Part", game:GetService("ReplicatedStorage"));
task.wait(5);
myPart:SetAttribute("test", true);
print("Fired it!");
--Client
local myPart = game:GetService("ReplicatedStorage"):WaitForChild("Part");
myPart:GetAttributeChangedSignal("test", function()
	warn("Yes, it detected it!");
end);

print("Listening!");

“Listening!” prints first and then “Fired it!” prints next. However, “Yes, it detected it!” never prints. Is there a way I can detect these changes without doing a loop or using remotes? Thanks.

3 Likes

Once again, the answer is to connect it properly and not via the second argument:

instance:GetAttributeChangedSignal("attribute"):Connect(function()
end);
Original Workaround

Workaround identified: For this situation I can just use a BoolValue since the .Changed event does fire when changed in the server. However, I would love if we would get the same for attributes since well… It just makes sense.

Note: Using :GetPropertyChangedSignal() also works which doesn’t make any sense to me since :GetAttributeChangedSignal() should also work using this logic

6 Likes

This is weird, I’ve been working with attributes for a long time, but I have encountered this just now. I can’t imagine it was not a feature from the start, I want to think that it broke. Bump

You didn’t connect it to the event. You provided the function as a second parameter which is never called. You have to do :Connect()

1 Like

Read my reply, he didn’t do it right.

The point still stands, using the event correctly with :Connect doesn’t fix the problem

1 Like

I pulled this from the official documentation:

local weapon = script.Parent

--- Listen for one specific attribute change
weapon:GetAttributeChangedSignal("ReloadTime"):Connect(function()
	print(weapon:GetAttribute("ReloadTime"))
end)

-- Listen for any attribute change on the instance
weapon.AttributeChanged:Connect(function(attributeName)
	print(attributeName, weapon:GetAttribute(attributeName))
end)
3 Likes

It does, I had that issue too and then I realized, OH THATS WHY

2 Likes

@Rabbit_Lord @FuneeDev You are right guys, I tested this exact code and it works. Some unexpected behavior was happening in my game, and I thought its a bug with the attribute feature itself, but has turned out to be my fault. Thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.