(This is my first post here. I apologize for any mistakes regarding posting and whatnot.)
I am trying to make a computer in Roblox Studio that turns on and off when a power button is pressed. My issue here is that the computer can only turn on and off ONCE.
Once it’s off, I’m not able to turn it on again when I click on the power button.
For instance; when I test out the game, the computer is off. I turn it on, then turn it back off. After that, I cannot turn it back on again.
I hope I’ve explained the issue clearly. Can someone help me fix this? I’m not a very experienced scripter.
I’ve looked at scripts for toggling lights as a reference, but haven’t really found any working solutions. I just don’t know what I’m missing.
local computer = script.Parent:WaitForChild('Computer')
local screen = computer.Model.Monitor:WaitForChild('Screen')
local screenlight = screen:WaitForChild('SurfaceLight')
local gui = screen:WaitForChild('SurfaceGui')
local powerbutton = computer.Parent.ComputerButton:WaitForChild('ClickDetector')
local frame = screen.SurfaceGui:WaitForChild('Frame')
local on = false
local debounce = true
screen.Transparency = 0
screen.Material = Enum.Material.SmoothPlastic;
screenlight.Brightness = 0
screen.SurfaceGui.Frame.BackgroundTransparency = 1
powerbutton.MouseClick:Connect(function()
if debounce and not on then
debounce = false
screen.Material = Enum.Material.Neon;
print('Turning on')
on = true
for i = 1,255 do
wait()
frame.BackgroundTransparency = frame.BackgroundTransparency - 0.039
screenlight.Brightness = screenlight.Brightness + 0.0039
end
wait(5)
debounce = true
else
if debounce then
debounce = false
print('Turning off')
on = false
for i = 1,255 do
wait()
frame.BackgroundTransparency = frame.BackgroundTransparency + 0.039
screenlight.Brightness = screenlight.Brightness - 0.039
end
screen.Material = Enum.Material.SmoothPlastic;
end
end
end)
Thanks in advance.