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

.changed event does not trigger switch function?

Asked by 2 years ago

hi, I am making a light bar, but I have a problem.

the issue is that when I change activated (boolean value)'s value to true, the lights don't flash!

I can tell by that I don't get "cool" on line 8 in output.

the script is in 1x2 light text (or block).

the activated bool value is in 1x2 light text (or block).

there is no error!

.changed that does not work is on line 60!

script:

---shortcuts
local block = script.Parent
local light = block.PointLight
local activate = block.activated

---function switch
function switch()
    print("cool")

    ---if activated is true
    if activate.Value == true then

        ---change transparency
        block.Transparency = 0

        ---activate light
        light.Enabled = true

        ---change material
        block.Material = Enum.Material.Neon

        ---loop
        while activate.Value == true do

            ---change color of block and light
            block.BrickColor = BrickColor.Red()
            light.Color = Color3.fromRGB(255, 0, 0)

            ---wait
            wait(math.random(1, 20) / 10)

            ---change color of block and light
            block.BrickColor = BrickColor.Blue()
            light.Color = Color3.fromRGB(0, 0, 255)

            ---wait
            wait(math.random(1, 20) / 10)
        end
    end

    ---if activated is false
    if activate.Value == false then

        ---change transparency
        block.Transparency = 0.5

        ---change material
        block.Material = Enum.Material.Glass

        ---de-activate light
        light.Enabled = false

        ---change color of block and light
        block.BrickColor = BrickColor.White()
        light.Color = Color3.fromRGB(255, 255, 255)
    end
end

---triggers
activate.Changed:Connect(switch)
0
Is there any script that changes the value of the Activated?/ NotThatFamouss 605 — 2y
0
I don't know maybe instead of making two if statements, use an else if?? Also maybe use :GetPropertyChangedSignal("Value") instead of .Changed? ScentedTrashCan 16 — 2y
0
Try putting any script that changes the value of the Activated. NotThatFamouss 605 — 2y
0
What type of script is this? Where is it located? xInfinityBear 1777 — 2y
View all comments (2 more)
0
@xInfinityBear it's located inside a workspace part, and I think I know what's going on. NotThatFamouss 605 — 2y
0
If it's a local script then that's the issue, they don't run in the workspace. xInfinityBear 1777 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

One problem I noticed; You didn't even put anything to change the Value of the boolean. Try experimenting with these:

---shortcuts
local block = script.Parent
local light = block.PointLight
local activate = block.activated

---function switch
function switch()
    print("cool")

    ---if activated is true
    if activate.Value == true then

        ---change transparency
        block.Transparency = 0

        ---activate light
        light.Enabled = true

        ---change material
        block.Material = Enum.Material.Neon

        ---loop
        while activate.Value == true do

            ---change color of block and light
            block.BrickColor = BrickColor.Red()
            light.Color = Color3.fromRGB(255, 0, 0)

            ---wait
            wait(math.random(1, 20) / 10)

            ---change color of block and light
            block.BrickColor = BrickColor.Blue()
            light.Color = Color3.fromRGB(0, 0, 255)

            ---wait
            wait(math.random(1, 20) / 10)
        end

    end

    ---if activated is false
    if activate.Value == false then

        ---change transparency
        block.Transparency = 0.5

        ---change material
        block.Material = Enum.Material.Glass

        ---de-activate lights
        light.Enabled = false

        ---change color of block and light
        block.BrickColor = BrickColor.White()
        light.Color = Color3.fromRGB(255, 255, 255)
    end
end

---triggers
block.Touched:Connect(function(hit)
    activate.Value = not activate.Value
end)

activate.Changed:Connect(switch)

The script is listening for any changes in the property of activate. But you didn't do anything to change properties, therefore the script is not doing anything.

0
no actually, i have not implamented that in. i just switch it manually! but i will see if it will function if i write a command that changes the value jeremqpmfpi 41 — 2y
0
i just put game.Workspace:WaitForChild("1x2 light test").activated.Value = true in command line and got nothing jeremqpmfpi 41 — 2y
0
well the value did change, but nothing else jeremqpmfpi 41 — 2y
Ad

Answer this question