Power/Lightning System Issues

Hello everyone, basically I have made a value called “Power” when this BoolValue is true, the lights need to be on. If its false, the lights are meant to be off. Although the issue is that.

I tried testing this with this here script to see if the value worked as intended

while true do
workspace.Values.Power.Value = false
wait(3)
workspace.Values.Power.Value = true
wait(3)
end

Although the light never changed.

This is the script I used for the lights.

while true do
	if workspace.Values.Power.Value == true then
		script.Parent.Light.PointLight.Enabled.Value = true
	else
		script.Parent.Light.PointLight.Enabled.Value = false
	end
end

Any help would be appriciated!

i think this can help!

workspace.Values.Power.Changed:Connect(function()
if workspace.Values.Power.Value == true then
script.Parent.Light.PointLight.Enabled.Value = true
else
script.Parent.Light.PointLight.Enabled.Value = false
end
end)

Note: also i recommend using “task.wait()” instead of “wait()”

Are you changing the value in a LocalScript? If so, then you have to change it using a ServerScript (if ur second script is a ServerScript)

They are both server scripts. Atleast I think so, the first thing that pops up when you search “Script”.

Change ur second script with this

while true do
	if workspace.Values.Power.Value == true then
		script.Parent.Light.PointLight.Enabled = true
	else
		script.Parent.Light.PointLight.Enabled = false
	end
end

Thats literally the script I used. How is this meant to help.

I removed the .Value after the .Enabled

oh i am stupid lmao, trying it out right now.

Using “while true do” without wait/task.wait will make the Loop timeout.
(it may cause lag on some devices too)

I recommend using .Changed or GetPropertyChanged

Oh it actually worked!!! Thanks mate, but if you guys have any more recommendations I am willing to listen.

1 Like

Whoops, I didn’t even notice there wasn’t a yield xD

try this @Immebest

workspace.Values.Power:GetPropertyChangedSignal("Value"):Connect(function()
	if workspace.Values.Power.Value == true then
		script.Parent.Light.PointLight.Enabled.Value = true
	else
		script.Parent.Light.PointLight.Enabled.Value = false
	end
end)
1 Like

This hurts my brain, probably as I am new, I guess this is an event that detects the value being changed right?

1 Like

Yep, just replace your second script with the GetPropertyChangedSignal script.

Odd, didnt seem to work. Was this meant to be a sample or something?

Did any errors print out in the Output?

It didnt work because he forgot to delete the .Value after the .Enabled again!

He meant to write this

workspace.Values.Power:GetPropertyChangedSignal("Value"):Connect(function()
	if workspace.Values.Power.Value == true then
		script.Parent.Light.PointLight.Enabled= true
	else
		script.Parent.Light.PointLight.Enabled= false
	end
end)

Oh and I did some script improvements:

workspace.Values.Power:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Light.PointLight.Enabled = workspace.Values.Power.Value
end)
2 Likes

Workspace.Model.Light.Script:5: attempt to index boolean with ‘Value’

OOPS how did I miss that again xDD

yep this method should be better

Wow! Thats actually a really smart way of doing it ngl. You deserve my honorary respect for today.

1 Like