Changed event not working

I’m trying to use Changed Event in a boolean but it is not working

Script:

shopModule.gloves["1"]["Equipped"].Changed:Connect(function() end)

Error:

attempt to index boolean with 'Changed'

1 Like

I tried that and it did not work, it says attempted to index nil with 'Changed'

Try experimenting with GetPropertyChangedSignal.

You’ll also want to know that Roblox has a modified Changed value for ‘StringValue, BoolValue’ to only fire Changed for the Value only.

ValueBase objects, such as IntValue and StringValue , use a modified Changed event that fires with the contents of the Value property. As such, this method provides a way to detect changes in other properties of those objects. For example, to detect changes in the Name property of an IntValue , use IntValue:GetPropertyChangedSignal("Name"):Connect(someFunc) since the Changed event of IntValue objects only detect changes on the Value property.

shopModule.globes['1']:GetPropertyChangedSignal("Value"):Connect(function()

    --check value

end)
2 Likes

So why use ::GetPropertyChangedSignal("Value") ?
Just use the Changed event then if you’re just listening for a change in value.

That’s right, but since the non-inherited Changed event only fires for the Value property of ValueBase objects, it’s good to use this for fewer-looking code.

@Guaxinim_975

The issue here is that

Is a boolean.

Please try to debug your code before posting, there could be various things wrong with your implementation (i.e you’re looking for a Changed event in a boolean value, not calling :WaitForChild() even though you’re indexing from the client and there’s the chance the instance wouldn’t have replicated when indexing etc).

If ‘gloves’ is the Value object, then bind a function to its Changed event.

It’s just a suggestion to change your idea on how to use Changed in general.

ValueBase objects do have a modified Changed event to only monitor Value but it’s a more healthy habit to always ise GetPropertyChangedSignal for everything.

Not 100% sure if this is the actually issue; as you didn’t give us enough info to work with; but is shopModule.gloves["1"]["Equipped"] an instance (something you can see in the Explorer tab in studio) or a variable in a script? .Changed and :GetPropertyChangedSignal("Value") only work with instances.

it’s a variable in a script

shopModule.gloves = {

["1"] = {

["Equipped"] = false;

};

}

that is why it’s not working, it only works for instances. You’d need something like this:

repeat
    wait() --I'd recommend using RunService.Heartbeat, as wait has many issues
until ["Equipped"] == Value
--rest of code

Like I said, .Changed only works on instances.

If you prefer an event driven function, you’d create a bindable event that you fire when it changes.

1 Like

I thought about that, but wouldn’t having wait statements for each item, cause lag?

Which is why I suggested having an event you fire when something is changed, but if you are waiting for something to change constantly, you might consider changing the way you handle this system.

1 Like