Is there any advice that I can get on how to improve my script (This is for a Emergency Vehicle/Police Car Lighting System)
local function on(p)
p.Transparency = 0.02
if p:FindFirstChild("Light") then
p.Light.Enabled = true
p.Light.Color = p.Color
end
end
local function off(p)
p.Transparency = 1
if p:FindFirstChild("Light") then
p.Light.Enabled = false
p.Light.Color = p.Color
end
end
Although your code seems a little repetitive, I think it’s fine because it’s such a small script and your two functions have a clear name and purpose.
p.Light.Color = p.Color is redundant because you’re setting it to the same thing in both functions.
Personally, this is how I would have done it:
local function adjustLight(p, transparency, enabled)
p.Transparency = transparency
if p:FindFirstChild("Light") then
p.Light.Enabled = enabled
end
end
local function on(p)
adjustLight(p, 0.02, true)
end
local function off(p)
adjustLight(p, 1, false)
end