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

Value not updating when changed?

Asked by
Nump4d 5
2 years ago
local PEmitter = script.Parent:GetChildren()
local EmitVal = script.Parent.Emit.Value

local function onEmit()
    for i, child in ipairs (PEmitter) do
        local Particles = child:GetChildren()
        for i, child in ipairs(Particles) do
            child.Enabled = EmitVal
        end
    end
end

script.Parent.Emit:GetPropertyChangedSignal("Value"):Connect(onEmit)

The script is placed inside a folder in workspace with the bool value (Emit) and parts that all have a ParticleEmitter in them. When the bool value changes it will change the enabled value of all the ParticleEmittes. I tried Changed as well and it did not work. The value is simply just not updating with the methods I am trying. Any help would be greatly appreciated

1 answer

Log in to vote
0
Answered by 2 years ago

The same issue was addressed in an old question, but allow me to explain.

In line 02, you are SETTING the variable into that property value as a memory. Therefore when you call it, it's gonna return the value that was previously set.

For example:

-- In this case, the BoolValue is false
local bool = script.BoolValue.Value

script.BoolValue.Value = true
task.wait()
print(bool)

Output:

false

It doesn't matter if you changed the value. The script will only take the variable's value, and since it was set to be false, it will print false. In other words, the variable doesn't update by itself unless if you told it to.

I am sorry if I didn't make myself clear, I'm not good at explaining stuff.

Ad

Answer this question