Why is the function looping?

This is not an issue, but why does this non loop looping and is this roblox studio bug or script issue?

Script:


script.Parent.Changed:Connect(function()
    local touchparts = script.Parent:GetTouchingParts()
    for i,v in pairs(touchparts) do
        print(v.Name)
        if v:IsA("Part") and v.Name == "Wire" then
            v.Volt.Changed:Connect(function()
                if v.Volt.Value >= 1 then
                    print(v.Volt.Value)
                    script.Parent.Material = Enum.Material.Neon
                    wait(1)
                    script.Parent.Material = startingmaterial
                end
            end)
        end
    end
end)

It printed 150 times, and the change function will be done manually, I mean I will change the position and its anchored to, but why is it running many times

Changed detects every property change except physics based ones like position, orientation, cframe, etc. Thus, it fires so many times. Also, why is there a nested Changed block? :thinking:

1 Like

But the event should fire when I move the part only right

your changing the material of script.parent inside script.parent.changed

you can also do :GetPropertyChangedSignal(“PropertyName”)

1 Like

But its 1 change? so it will fire 1 time I guess does it fire loop?

Everytime a change is created, it creates a connection. Note: Some changes are made by core scripts, not by the user.

1 Like

signals don’t run just once, they run every time it gets fired, since your changing the material you are firing the changed event again

you can make them run once by doing

local signal--initialize the variable
signal = part.Changed:Connect(function()
	signal:Disconnect()
end)
1 Like

I told function loop not parts loop if you have read the topic fully

I’ve renamed the topic, ok and its not trash topic stop being rude

Please stop with this kind of behavior. This is really unprofessional and childish.

1 Like

Ay yo. There is no need to use the sort of language you are using. If you’re angry, go vent it out somewhere else, we don’t need to hear your complaints on a perfectly reasonable topic, or anywhere else on the forum. If you can’t handle “idiotic topics”, then maybe don’t click on them. It will save you the energy of using your hand to click and type your childish complaints, and it will save us the headache of reading and dealing with it.