✓ Accepted answer
Well first let's add a variable that either says the lights are on or not
local lights=false
Next let's add it to the start of your script
local car = script.Parent.Car.Value
local mouse=game.Players.LocalPlayer:GetMouse()
local lights = false
mouse.KeyDown:connect(function(key)
end)
Now let's check if the lights are on or not if on do this if not then do that
local car = script.Parent.Car.Value
local mouse=game.Players.LocalPlayer:GetMouse()
local lights = false
mouse.KeyDown:connect(function(key)
if lights==false then
elseif lights==true then
end
end)
Now let's tell it what to do if the lights are off, also in the loop we will check that lights is still == to true
local car = script.Parent.Car.Value
local mouse=game.Players.LocalPlayer:GetMouse()
local lights = false
mouse.KeyDown:connect(function(key)
if key=="e" then
if lights==false then lights=true
while lights == true do
wait(1/27)
car.Body.RIGHT.Material = "Neon"
car.Body.RIGHT.Transparency = 0
wait(1/27)
car.Body.RIGHT.Material = "SmoothPlastic"
car.Body.RIGHT.Transparency = 1
end
elseif lights==true then lights=false
end
end
end)
Now what happens when its false
local car = script.Parent.Car.Value
local mouse=game.Players.LocalPlayer:GetMouse()
local lights = false
mouse.KeyDown:connect(function(key)
if key=="e" then
if lights==false then lights=true
while lights == true do
car.Body.RIGHT.Material = "Neon"
car.Body.RIGHT.Transparency = 0
wait(1/27)
car.Body.RIGHT.Material = "SmoothPlastic"
car.Body.RIGHT.Transparency = 1
wait(1/27)
end
elseif lights==true then lights=false
car.Body.RIGHT.Material = "SmoothPlastic"
car.Body.RIGHT.Transparency = 1
end
end
end)
3 comments
Thank you very much!! I understand now, and the script you provided works perfectly.
Using key == "e" is extremely ineffective, and not recommended. Use the ContextActionService or UserInputService instead.
^ forgot about that.