Hello, I have this script and I need it to be constantly checking if the value is true and if it is it will spin the parts exc. and also it needs to turn off if the value is false. Here is the script:
sp=script.Parent
bulb=sp:WaitForChild("Bulb")
part1=sp:WaitForChild("Part1")
light1=part1:WaitForChild("SpotLight")
part2=sp:WaitForChild("Part2")
light2=part2:WaitForChild("SpotLight")
toggle=sp:WaitForChild("Toggle")
function updatetoggle()
bulb.BrickColor=(toggle.Value and BrickColor.new("Really red")) or BrickColor.new("Mid gray")
light1.Enabled=toggle.Value
light2.Enabled=toggle.Value
end
toggle.Changed:connect(updatetoggle)
updatetoggle()
rate=1/30
rps=1
currentrotation=math.random()
while true do
wait(.1)
while toggle.Value do
wait(rate)
currentrotation=currentrotation+(rps*rate)
part1.CFrame=((bulb.CFrame*CFrame.Angles(0,math.pi*2*currentrotation,0))*CFrame.Angles(0,0,math.pi*.5))*CFrame.new(0,0,part1.Size.z*.5)
part2.CFrame=((bulb.CFrame*CFrame.Angles(0,math.pi*2*(currentrotation+.5),0))*CFrame.Angles(0,0,math.pi*.5))*CFrame.new(0,0,part2.Size.z*.5)
end
end
function updatetoggle()
bulb.BrickColor=(toggle.Value and BrickColor.new(“Really red”)) or BrickColor.new(“Mid gray”)
light1.Enabled=toggle.Value
light2.Enabled=toggle.Value
end
while true do
wait(.1)
while toggle.Value do
wait(rate)
currentrotation=currentrotation+(rpsrate)
part1.CFrame=((bulb.CFrameCFrame.Angles(0,math.pi2currentrotation,0))CFrame.Angles(0,0,math.pi.5))CFrame.new(0,0,part1.Size.z.5)
part2.CFrame=((bulb.CFrameCFrame.Angles(0,math.pi2*(currentrotation+.5),0))CFrame.Angles(0,0,math.pi.5))CFrame.new(0,0,part2.Size.z.5)
end
end
You can do toggle:GetPropertyChangedSignal and choose which property the event will fire for. But if you like literally want to be constantly checking if a value is true, you can use a while loop condition.
Example 1:
toggle:GetPropertyChangedSignal("PropertyName"):Connect(function()
if toggle == true then
print("True")
end
end)
Example 2:
while toggle == true do
print("True")
task.wait() -- This is to stop the script from crashing as while loops run so fast
end
I suggest not using :wait as it’s deprecated. task.wait() is the new version and it works better if you didn’t know. Also I think you could use less while loops as it’s using up quite alot of resources. There is no need for a while true do loop and also a while toggleValue do loop aswell. You can just do while toggle == true do which will ensure the loop will only run if the toggle value is true but it will also constantly check the conditions of toggle.
So by that I meant insert the property name for the property you want to check that has changed. (eg, names, brickcolors, etc). I can’t remember exactly but I think in your case you wanted to check if toggle.Value == true?
To do this:
Redone example 1 after 7 months:
toggle:GetPropertyChangedSignal("Value"):Connect(function()
-- This event will fire if the value is changed to either false or true so you need to check if its true with an if statement
if toggle == true then
print("Toggle's value is True")
end
end)