Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wait(0.1)
- seat = script.Parent:WaitForChild("Seat")
- seat = seat.Value
- lock = false
- steer = 0
- throttle = 0
- gear = 1
- maxgear = 12
- local gearlabel = script.Parent:WaitForChild("Gear")
- gearlabel.Parent.Gear.Text = (gear.."/"..maxgear)
- Player = game.Players.LocalPlayer
- left = {}
- right = {}
- brakelight = {}
- rearlight = {}
- leftturn = {}
- rightturn = {}
- leftlight = {}
- rightlight = {}
- leftbrake = {}
- rightbrake = {}
- leftflash = {}
- rightflash = {}
- headlight = {}
- revlight = {}
- lightson = false
- turningleft = false
- turningright = false
- turndebounce = false
- local EMSirens = script.Parent:WaitForChild("EM_Sirens")
- local EMControl = script.Parent:WaitForChild("EM_Controler")
- EMSirens.Disabled = false
- EMControl.Disabled = false
- ha=false
- hd=false
- hs=false
- hw=false
- events = {
- lights = seat.FilteringEnabled.headlights,
- sound = seat.FilteringEnabled.sound,
- destroycar = seat.FilteringEnabled.destroyCar
- }
- imgassets ={
- hazardoff="http://www.roblox.com/asset/?id=116525460",
- hazardon = "http://www.roblox.com/asset/?id=116525473",
- leftyoff = "http://www.roblox.com/asset/?id=116525490",
- leftyon = "http://www.roblox.com/asset/?id=116525499",
- rightyoff = "http://www.roblox.com/asset/?id=116525510",
- rightyon = "http://www.roblox.com/asset/?id=116525535",
- lightsoff = "http://www.roblox.com/asset/?id=115931775",
- lightson = "http://www.roblox.com/asset/?id=115931779",
- lockoff = "http://www.roblox.com/asset/?id=116532096",
- lockon = "http://www.roblox.com/asset/?id=116532114",
- leftturn = "http://www.roblox.com/asset/?id=115931542",
- rightturn = "http://www.roblox.com/asset/?id=115931529",
- fltd = "http://www.roblox.com/asset/?id=116531501",
- }
- for _,i in pairs (imgassets) do
- game:GetService("ContentProvider"):Preload(i)
- end
- if gear == 1 then
- script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
- script.Parent.dn.Style = "RobloxButton"
- end
- if gear == maxgear then
- script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
- script.Parent.up.Style = "RobloxButton"
- end
- function gearup()--activated by GUI or pressing E
- if lock then return end
- if gear < maxgear then
- gear = gear+1
- watdo()
- script.Parent.Gear.Text = (gear.."/"..maxgear)
- end
- if gear == maxgear then
- script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
- script.Parent.up.Style = "RobloxButton"
- script.Parent.dn.TextColor3 = Color3.new(1,1,1)
- script.Parent.dn.Style = "RobloxButtonDefault"
- elseif gear == 1 then
- script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
- script.Parent.dn.Style = "RobloxButton"
- script.Parent.up.TextColor3 = Color3.new(1,1,1)
- script.Parent.up.Style = "RobloxButtonDefault"
- else
- script.Parent.dn.TextColor3 = Color3.new(1,1,1)
- script.Parent.dn.Style = "RobloxButtonDefault"
- script.Parent.up.TextColor3 = Color3.new(1,1,1)
- script.Parent.up.Style = "RobloxButtonDefault"
- end
- end
- function geardown()--activated by GUI or pressing Q
- if lock then return end
- if gear > 1 then
- gear = gear-1
- watdo()
- script.Parent.Gear.Text = (gear.."/"..maxgear)
- end
- if gear == 1 then
- script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
- script.Parent.dn.Style = "RobloxButton"
- script.Parent.up.TextColor3 = Color3.new(1,1,1)
- script.Parent.up.Style = "RobloxButtonDefault"
- elseif gear == maxgear then
- script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
- script.Parent.up.Style = "RobloxButton"
- script.Parent.dn.TextColor3 = Color3.new(1,1,1)
- script.Parent.dn.Style = "RobloxButtonDefault"
- else
- script.Parent.dn.TextColor3 = Color3.new(1,1,1)
- script.Parent.dn.Style = "RobloxButtonDefault"
- script.Parent.up.TextColor3 = Color3.new(1,1,1)
- script.Parent.up.Style = "RobloxButtonDefault"
- end
- end
- script.Parent.up.MouseButton1Click:connect(gearup)
- script.Parent.dn.MouseButton1Click:connect(geardown)
- script.Parent.flipbutton.MouseButton1Click:connect(function()
- if not flipping then
- flipping = true
- script.Parent.flipbutton.ImageColor3 = Color3.new(170,0,0)
- local a = Instance.new("BodyPosition",seat)
- a.maxForce = Vector3.new(100000,10000000,100000)
- a.position = seat.Position + Vector3.new(0,10,0)
- local b = Instance.new("BodyGyro",seat)
- wait(3)
- a:Destroy()
- b:Destroy()
- flipping = false
- script.Parent.flipbutton.ImageColor3 = Color3.new(255,255,255)
- end
- end)
- function turn()
- if turndebounce == false then
- turndebounce = true
- wait(0.05)
- repeat
- local templeft = turningleft
- local tempright = turningright
- script.Parent.onsound:Play()
- if turningleft == true then
- script.Parent.leftturn.ImageTransparency = 0
- for _,i in pairs (leftturn) do
- i.BrickColor = BrickColor.new("Deep orange")
- i.Material = "Neon"
- end
- for _,a in pairs (leftlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Neon"
- end
- for _,b in pairs (leftflash) do
- if lightson then
- b.Enabled = true
- end
- end
- for _,b in pairs (leftbrake) do
- b.Brightness = 2
- end
- end
- if turningright == true then
- script.Parent.rightturn.ImageTransparency = 0
- for _,i in pairs (rightturn) do
- i.BrickColor = BrickColor.new("Deep orange")
- i.Material = "Neon"
- end
- for _,a in pairs (rightlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Neon"
- end
- for _,b in pairs (rightflash) do
- if lightson then
- b.Enabled = true
- end
- end
- for _,b in pairs (rightbrake) do
- b.Brightness = 2
- end
- end
- wait(0.4)
- script.Parent.offsound:Play()
- script.Parent.leftturn.ImageTransparency = 0.9
- script.Parent.rightturn.ImageTransparency = 0.9
- if templeft == true then
- for _,i in pairs (leftturn) do
- i.BrickColor = BrickColor.new("Neon orange")
- i.Material = "Metal"
- end
- for _,b in pairs (leftflash) do
- b.Enabled = false
- end
- for _,a in pairs (leftlight) do
- a.BrickColor = BrickColor.new("Bright red")
- a.Material = "Metal"
- end
- for _,b in pairs (leftbrake) do
- b.Brightness = 1
- end
- else
- if throttle > 0 then
- for _,a in pairs (leftlight) do
- a.BrickColor = BrickColor.new("Bright red")
- a.Material = "Metal"
- end
- for _,b in pairs (leftbrake) do
- b.Brightness = 1
- end
- else
- for _,a in pairs (leftlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Neon"
- end
- for _,b in pairs (leftbrake) do
- b.Brightness = 2
- end
- end
- end
- if tempright == true then
- for _,i in pairs (rightturn) do
- i.BrickColor = BrickColor.new("Neon orange")
- i.Material = "Metal"
- end
- for _,b in pairs (rightflash) do
- b.Enabled = false
- end
- for _,a in pairs (rightlight) do
- a.BrickColor = BrickColor.new("Bright red")
- a.Material = "Metal"
- end
- for _,b in pairs (rightbrake) do
- b.Brightness = 1
- end
- else
- if throttle > 0 then
- for _,a in pairs (rightlight) do
- a.BrickColor = BrickColor.new("Bright red")
- a.Material = "Metal"
- end
- for _,b in pairs (rightbrake) do
- b.Brightness = 1
- end
- else
- for _,a in pairs (rightlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Neon"
- end
- for _,b in pairs (rightbrake) do
- b.Brightness = 2
- end
- end
- end
- wait(0.35)
- until turningleft == false and turningright == false
- turndebounce = false
- end
- end
- seat.ChildRemoved:connect(function(it)
- if it:IsA("Weld") then
- if it.Part1.Parent == Player.Character then
- script.Parent.EM_Sirens.Disabled = true
- script.Parent.ELS_Status.SirenStatus.Locked.Visible = true
- script.Parent.ELS_Status.SirenStatus.MBOV.Visible = true
- lock = true
- ha=false
- hd=false
- hs=false
- hw=false
- throttle = 0
- steer = 0
- watdo()
- script.Parent.close.Active = true
- script.Parent.close.Visible = true
- script.Parent.xlabel.Visible = true
- end
- end
- end)
- seat.ChildAdded:connect(function(it)
- if it:IsA("Weld") then
- if it.Part1.Parent == Player.Character then
- script.Parent.EM_Sirens.Disabled = false
- script.Parent.ELS_Status.SirenStatus.Locked.Visible = false
- script.Parent.ELS_Status.SirenStatus.MBOV.Visible = true
- lock = false
- script.Parent.close.Active = false
- script.Parent.close.Visible = false
- script.Parent.xlabel.Visible = false
- end
- end
- end)
- function exiting()
- lock = true--when we close the gui stop everything
- steer = 0
- throttle = 0
- watdo()
- turningleft = false
- turningright = false
- lightson = false
- seat.exit:FireServer()
- for _,i in pairs (leftturn) do
- i.BrickColor = BrickColor.new("Neon orange")
- i.Material = "Metal"
- end
- for _,a in pairs (leftlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Metal"
- end
- for _,b in pairs (leftflash) do
- b.Enabled = false
- end
- for _,b in pairs (leftbrake) do
- b.Brightness = 2
- end
- for _,i in pairs (rightturn) do
- i.BrickColor = BrickColor.new("Neon orange")
- i.Material = "Metal"
- end
- for _,a in pairs (rightlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Metal"
- end
- for _,b in pairs (rightflash) do
- b.Enabled = false
- end
- for _,b in pairs (rightbrake) do
- b.Brightness = 2
- end
- script.Parent.Parent:Destroy()--destroy the 'Car' ScreenGui
- end
- function updatelights()
- for _,i in pairs (leftbrake) do
- i.Enabled = lightson
- end
- for _,i in pairs (rightbrake) do
- i.Enabled = lightson
- end
- for _,i in pairs (brakelight) do
- i.Enabled = lightson
- end
- for _,i in pairs (headlight) do
- i.Enabled = lightson
- end
- if lightson then
- script.Parent.lightimage.Image = imgassets.lightson
- else
- script.Parent.lightimage.Image = imgassets.lightsoff
- end
- end
- script.Parent.lights.MouseButton1Click:connect(function()
- if lock then return end
- lightson = not lightson
- events.lights:FireServer(lightson)
- if lightson then
- script.Parent.lightimage.Image = imgassets.lightson
- else
- script.Parent.lightimage.Image = imgassets.lightsoff
- end
- end)
- function destroycar()
- events.destroycar:FireServer(seat.Parent)
- script.Parent.Parent:Destroy()
- end
- script.Parent.close.MouseButton1Up:connect(exiting)
- Player.Character.Humanoid.Died:connect(destroycar)
- game.Players.PlayerRemoving:connect(function(Playeras)
- if Playeras.Name == Player.Name then
- destroycar()
- end
- end)
- for _, i in pairs (seat.Parent:GetChildren()) do--populate the tables for ease of modularity. You could have 100 left wheels if you wanted.
- if i.Name == "LeftWheel" then
- table.insert(left,i)
- elseif i.Name == "RightWheel" then
- table.insert(right,i)
- elseif i.Name == "Rearlight" then
- table.insert(rearlight,i)
- elseif i.Name == "Brakelight" then
- table.insert(brakelight,i.SpotLight)
- elseif i.Name == "rightturn" then
- table.insert(rightturn,i)
- elseif i.Name == "leftturn" then
- table.insert(leftturn,i)
- elseif i.Name == "leftflash" then
- table.insert(leftflash,i.SpotLight)
- elseif i.Name == "rightflash" then
- table.insert(rightflash,i.SpotLight)
- elseif i.Name == "leftlight" then
- table.insert(leftlight,i)
- elseif i.Name == "rightlight" then
- table.insert(rightlight,i)
- elseif i.Name == "Headlight" then
- table.insert(headlight,i.SpotLight)
- elseif i.Name == "leftbrake" then
- table.insert(leftbrake,i.SpotLight)
- elseif i.Name == "rightbrake" then
- table.insert(rightbrake,i.SpotLight)
- elseif i.Name == "revlight" then
- table.insert(revlight,i.SpotLight)
- end
- end
- for _,l in pairs (left) do
- l.BottomParamA = 0
- l.BottomParamB = 0
- end
- for _,r in pairs (right) do
- r.BottomParamA = 0
- r.BottomParamB = 0
- end
- function watdo()
- seat.Parent.LeftMotor.DesiredAngle = math.rad(throttle < 0 and 40* steer or 40*steer/gear^0.5)
- seat.Parent.RightMotor.DesiredAngle = math.rad(throttle < 0 and 40* steer or 40*steer/gear^0.5)
- for _,l in pairs (left) do--I do it this way so that it's not searching the model every time an input happens
- if throttle ~= -1 then
- l.BottomParamA = (.1/gear)
- l.BottomParamB = (.5*gear+steer*gear/30)*throttle
- else
- l.BottomParamA = -.01
- l.BottomParamB = -.5-steer/20
- end
- end
- for _,r in pairs (right) do
- if throttle ~= -1 then
- r.BottomParamA = -(.1/gear)
- r.BottomParamB = -(.5*gear-steer*gear/30)*throttle
- else
- r.BottomParamA = .01
- r.BottomParamB = .5-steer/20
- end
- end
- if throttle < 1 then
- for _,g in pairs (rearlight) do
- g.BrickColor = BrickColor.new("Really red")
- g.Material = "Neon"
- end
- for _,b in pairs (brakelight) do
- b.Brightness = 2
- end
- if turningleft == false then
- for _,a in pairs (leftlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Neon"
- end
- for _,b in pairs (leftbrake) do
- b.Brightness = 2
- end
- end
- if turningright == false then
- for _,a in pairs (rightlight) do
- a.BrickColor = BrickColor.new("Really red")
- a.Material = "Neon"
- end
- for _,b in pairs (rightbrake) do
- b.Brightness = 2
- end
- end
- else
- for _,g in pairs (rearlight) do
- g.BrickColor = BrickColor.new("Bright red")
- g.Material = "Metal"
- end
- for _,b in pairs (brakelight) do
- b.Brightness = 1
- end
- if turningleft == false then
- for _,a in pairs (leftlight) do
- a.BrickColor = BrickColor.new("Bright red")
- a.Material = "Metal"
- end
- for _,b in pairs (leftbrake) do
- b.Brightness = 1
- end
- end
- if turningright == false then
- for _,a in pairs (rightlight) do
- a.BrickColor = BrickColor.new("Bright red")
- a.Material = "Metal"
- end
- for _,b in pairs (rightbrake) do
- b.Brightness = 1
- end
- end
- end
- if throttle < 0 then
- for _,b in pairs (revlight) do
- if lightson then
- b.Parent.Material = "Neon"
- b.Enabled = true
- end
- end
- else
- for _,b in pairs (revlight) do
- b.Parent.Material = "Metal"
- b.Enabled = false
- end
- end
- end
- Player:GetMouse().KeyDown:connect(function(key)--warning ugly button code
- if lock then return end
- key = string.upper(key)
- if not ha and key == "A" or key == string.char(20) and not ha then
- ha = true
- steer = steer-1
- end
- if not hd and key == "D" or key == string.char(19) and not hd then
- hd = true
- steer = steer+1
- end
- if not hw and key == "W" or key == string.char(17) and not hw then
- hw = true
- throttle = throttle+1
- end
- if not hs and key == "S" or key == string.char(18) and not hs then
- hs = true
- throttle = throttle-1
- end
- if key == "Z" then
- geardown()
- end
- if key == "X" then
- gearup()
- end
- if key == "Q" then
- turningleft = not turningleft
- turn()
- end
- if key == "E" then
- turningright = not turningright
- turn()
- end
- watdo()
- end)
- Player:GetMouse().KeyUp:connect(function(key)
- if lock then return end
- key = string.upper(key)
- if ha and key == "A" or key == string.char(20)and ha then
- steer = steer+1
- ha = false
- end
- if hd and key == "D" or key == string.char(19) and hd then
- steer = steer-1
- hd = false
- end
- if hw and key == "W" or key == string.char(17) and hw then
- throttle = throttle-1
- hw = false
- end
- if hs and key == "S" or key == string.char(18) and hs then
- throttle = throttle+1
- hs = false
- end
- if key == "" then
- --more keys if I need them
- end
- watdo()
- end)
- while true do
- wait(0.1)
- script.Parent.Speed.Text = ("Speed: "..math.floor(seat.Velocity.Magnitude/2))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement