Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

.changed event does not trigger switch function?

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)

6 comments

0

Is there any script that changes the value of the Activated?/

0

I don't know maybe instead of making two if statements, use an else if?? Also maybe use :GetPropertyChangedSignal("Value") instead of .Changed?

0

Try putting any script that changes the value of the Activated.

0

What type of script is this? Where is it located?

0

@xInfinityBear it's located inside a workspace part, and I think I know what's going on.

0

If it's a local script then that's the issue, they don't run in the workspace.

1 answer

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.

3 comments

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

0

i just put game.Workspace:WaitForChild("1x2 light test").activated.Value = true in command line and got nothing

0

well the value did change, but nothing else

This discussion is preserved as it was. New answers, comments, and votes are closed.