Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way i can simplify this script?

I just wan't to make this script smaller, because of my sloppy scripting i dont know how :p

--Detector for Veichle Seats

--ForwardChange(1)
script.Parent.VehicleSeat.Changed:connect(function()
     if script.Parent.VehicleSeat.Throttle == 1 then
		ForwardChange()
	end
end)

--ForwardChange(2)
function ForwardChange()
	script.Parent.Forward.BrickColor = BrickColor.new("Really red")
end

--ForwardChange(3)
script.Parent.VehicleSeat.Changed:connect(function()
     if script.Parent.VehicleSeat.Throttle == 0 or -1 then
		script.Parent.Forward.BrickColor = BrickColor.Black()
	end
end)
--barr


--BackWardChange
script.Parent.VehicleSeat.Changed:connect(function()
     if script.Parent.VehicleSeat.Throttle == -1 then
		BackWardChange()
	end
end)

--BackWardChange(2)
function BackWardChange()
	script.Parent.Backward.BrickColor = BrickColor.new("Really red")
end

--BackWardChange(3)
script.Parent.VehicleSeat.Changed:connect(function()
     if script.Parent.VehicleSeat.Throttle == 0 or 1 then
		script.Parent.Backward.BrickColor = BrickColor.Black()
	end
end)

1 comment

0

Well it doesn't have to be compact. The point of writing clean code is for the user to be able to read it. But I'll give it a shot xD

1 answer

✓ Accepted answer
--Detector for Veichle Seats

--ForwardChange(1)
script.Parent.VehicleSeat.Changed:connect(function()
     if script.Parent.VehicleSeat.Throttle == 1 then
        script.Parent.Forward.BrickColor = BrickColor.new("Really red")
    elseif script.Parent.VehicleSeat.Throttle <= 0 then
        script.Parent.Forward.BrickColor = BrickColor.Black()
        if script.Parent.VehicleSeat.Throttle == -1 then
            script.Parent.Backward.BrickColor = BrickColor.new("Really red")
        elseif script.Parent.VehicleSeat.Throttle >= 1 then
            script.Parent.Backward.BrickColor = BrickColor.Black()
        end
    end
end)

Lol, try it. The odds are it won't work but I don't have access to any form of debugging software as I'm in school right now. But it might work xD. Good luck!

This discussion is preserved as it was. New answers, comments, and votes are closed.