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'
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'
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 asIntValue
andStringValue
, use a modifiedChanged
event that fires with the contents of theValue
property. As such, this method provides a way to detect changes in other properties of those objects. For example, to detect changes in theName
property of anIntValue
, useIntValue:GetPropertyChangedSignal("Name"):Connect(someFunc)
since theChanged
event ofIntValue
objects only detect changes on theValue
property.
shopModule.globes['1']:GetPropertyChangedSignal("Value"):Connect(function()
--check value
end)
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.
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.