Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.29 KB | None | 0 0
  1. wait(0.1)
  2. seat = script.Parent:WaitForChild("Seat")
  3. seat = seat.Value
  4. lock = false
  5. steer = 0
  6. throttle = 0
  7. gear = 1
  8. maxgear = 12
  9. local gearlabel = script.Parent:WaitForChild("Gear")
  10. gearlabel.Parent.Gear.Text = (gear.."/"..maxgear)
  11. Player = game.Players.LocalPlayer
  12. left = {}
  13. right = {}
  14. brakelight = {}
  15. rearlight = {}
  16. leftturn = {}
  17. rightturn = {}
  18. leftlight = {}
  19. rightlight = {}
  20. leftbrake = {}
  21. rightbrake = {}
  22. leftflash = {}
  23. rightflash = {}
  24. headlight = {}
  25. revlight = {}
  26. lightson = false
  27. turningleft = false
  28. turningright = false
  29. turndebounce = false
  30. local EMSirens = script.Parent:WaitForChild("EM_Sirens")
  31. local EMControl = script.Parent:WaitForChild("EM_Controler")
  32.  
  33. EMSirens.Disabled = false
  34. EMControl.Disabled = false
  35.  
  36. ha=false
  37. hd=false
  38. hs=false
  39. hw=false
  40.  
  41.  
  42.  
  43. events = {
  44.     lights = seat.FilteringEnabled.headlights,
  45.     sound = seat.FilteringEnabled.sound,
  46.     destroycar = seat.FilteringEnabled.destroyCar
  47. }
  48. imgassets ={
  49.     hazardoff="http://www.roblox.com/asset/?id=116525460",
  50.     hazardon = "http://www.roblox.com/asset/?id=116525473",
  51.     leftyoff = "http://www.roblox.com/asset/?id=116525490",
  52.     leftyon = "http://www.roblox.com/asset/?id=116525499",
  53.     rightyoff = "http://www.roblox.com/asset/?id=116525510",
  54.     rightyon = "http://www.roblox.com/asset/?id=116525535",
  55.     lightsoff = "http://www.roblox.com/asset/?id=115931775",
  56.     lightson = "http://www.roblox.com/asset/?id=115931779",
  57.     lockoff = "http://www.roblox.com/asset/?id=116532096",
  58.     lockon = "http://www.roblox.com/asset/?id=116532114",
  59.     leftturn = "http://www.roblox.com/asset/?id=115931542",
  60.     rightturn = "http://www.roblox.com/asset/?id=115931529",
  61.     fltd = "http://www.roblox.com/asset/?id=116531501",
  62. }
  63. for _,i in pairs (imgassets) do
  64.     game:GetService("ContentProvider"):Preload(i)
  65. end
  66.  
  67. if gear == 1 then
  68.     script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
  69.     script.Parent.dn.Style = "RobloxButton"
  70. end
  71. if gear == maxgear then
  72.     script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
  73.     script.Parent.up.Style = "RobloxButton"
  74. end
  75.  
  76. function gearup()--activated by GUI or pressing E
  77.     if lock then return end
  78.     if gear < maxgear then
  79.         gear = gear+1
  80.         watdo()
  81.         script.Parent.Gear.Text = (gear.."/"..maxgear)
  82.     end
  83.     if gear == maxgear then
  84.         script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
  85.         script.Parent.up.Style = "RobloxButton"
  86.         script.Parent.dn.TextColor3 = Color3.new(1,1,1)
  87.         script.Parent.dn.Style = "RobloxButtonDefault"
  88.     elseif gear == 1 then
  89.         script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
  90.         script.Parent.dn.Style = "RobloxButton"
  91.         script.Parent.up.TextColor3 = Color3.new(1,1,1)
  92.         script.Parent.up.Style = "RobloxButtonDefault"
  93.     else
  94.         script.Parent.dn.TextColor3 = Color3.new(1,1,1)
  95.         script.Parent.dn.Style = "RobloxButtonDefault"
  96.         script.Parent.up.TextColor3 = Color3.new(1,1,1)
  97.         script.Parent.up.Style = "RobloxButtonDefault"
  98.     end
  99. end
  100. function geardown()--activated by GUI or pressing Q
  101.     if lock then return end
  102.     if gear > 1 then
  103.         gear = gear-1
  104.         watdo()
  105.         script.Parent.Gear.Text = (gear.."/"..maxgear)
  106.     end
  107.     if gear == 1 then
  108.         script.Parent.dn.TextColor3 = Color3.new(.3,.3,.3)
  109.         script.Parent.dn.Style = "RobloxButton"
  110.         script.Parent.up.TextColor3 = Color3.new(1,1,1)
  111.         script.Parent.up.Style = "RobloxButtonDefault"
  112.     elseif gear == maxgear then
  113.         script.Parent.up.TextColor3 = Color3.new(.3,.3,.3)
  114.         script.Parent.up.Style = "RobloxButton"
  115.         script.Parent.dn.TextColor3 = Color3.new(1,1,1)
  116.         script.Parent.dn.Style = "RobloxButtonDefault"
  117.     else
  118.         script.Parent.dn.TextColor3 = Color3.new(1,1,1)
  119.         script.Parent.dn.Style = "RobloxButtonDefault"
  120.         script.Parent.up.TextColor3 = Color3.new(1,1,1)
  121.         script.Parent.up.Style = "RobloxButtonDefault"
  122.     end
  123. end
  124.  
  125. script.Parent.up.MouseButton1Click:connect(gearup)
  126. script.Parent.dn.MouseButton1Click:connect(geardown)
  127.  
  128. script.Parent.flipbutton.MouseButton1Click:connect(function()
  129.     if not flipping then
  130.         flipping = true
  131.         script.Parent.flipbutton.ImageColor3 = Color3.new(170,0,0)
  132.         local a = Instance.new("BodyPosition",seat)
  133.         a.maxForce = Vector3.new(100000,10000000,100000)
  134.         a.position = seat.Position + Vector3.new(0,10,0)
  135.         local b = Instance.new("BodyGyro",seat)
  136.         wait(3)
  137.         a:Destroy()
  138.         b:Destroy()
  139.         flipping = false
  140.         script.Parent.flipbutton.ImageColor3 = Color3.new(255,255,255)
  141.     end
  142. end)
  143.  
  144. function turn()
  145.     if turndebounce == false then
  146.         turndebounce = true
  147.         wait(0.05)
  148.         repeat
  149.             local templeft = turningleft
  150.             local tempright = turningright
  151.             script.Parent.onsound:Play()
  152.             if turningleft == true then
  153.                 script.Parent.leftturn.ImageTransparency = 0
  154.                 for _,i in pairs (leftturn) do
  155.                     i.BrickColor = BrickColor.new("Deep orange")
  156.                     i.Material = "Neon"
  157.                 end
  158.                 for _,a in pairs (leftlight) do
  159.                     a.BrickColor = BrickColor.new("Really red")
  160.                     a.Material = "Neon"
  161.                 end
  162.                 for _,b in pairs (leftflash) do
  163.                     if lightson then
  164.                         b.Enabled = true
  165.                     end
  166.                 end
  167.                 for _,b in pairs (leftbrake) do
  168.                     b.Brightness = 2
  169.                 end
  170.             end
  171.             if turningright == true then
  172.                 script.Parent.rightturn.ImageTransparency = 0
  173.                 for _,i in pairs (rightturn) do
  174.                     i.BrickColor = BrickColor.new("Deep orange")
  175.                     i.Material = "Neon"
  176.                 end
  177.                 for _,a in pairs (rightlight) do
  178.                     a.BrickColor = BrickColor.new("Really red")
  179.                     a.Material = "Neon"
  180.                 end
  181.                 for _,b in pairs (rightflash) do
  182.                     if lightson then
  183.                         b.Enabled = true
  184.                     end
  185.                 end
  186.                 for _,b in pairs (rightbrake) do
  187.                     b.Brightness = 2
  188.                 end
  189.             end
  190.             wait(0.4)
  191.             script.Parent.offsound:Play()
  192.             script.Parent.leftturn.ImageTransparency = 0.9
  193.             script.Parent.rightturn.ImageTransparency = 0.9
  194.             if templeft == true then
  195.                 for _,i in pairs (leftturn) do
  196.                     i.BrickColor = BrickColor.new("Neon orange")
  197.                     i.Material = "Metal"
  198.                 end
  199.                 for _,b in pairs (leftflash) do
  200.                     b.Enabled = false
  201.                 end
  202.                 for _,a in pairs (leftlight) do
  203.                     a.BrickColor = BrickColor.new("Bright red")
  204.                     a.Material = "Metal"
  205.                 end
  206.                 for _,b in pairs (leftbrake) do
  207.                     b.Brightness = 1
  208.                 end
  209.             else
  210.                 if throttle > 0 then
  211.                     for _,a in pairs (leftlight) do
  212.                         a.BrickColor = BrickColor.new("Bright red")
  213.                         a.Material = "Metal"
  214.                     end
  215.                     for _,b in pairs (leftbrake) do
  216.                         b.Brightness = 1
  217.                     end
  218.                 else
  219.                     for _,a in pairs (leftlight) do
  220.                         a.BrickColor = BrickColor.new("Really red")
  221.                         a.Material = "Neon"
  222.                     end
  223.                     for _,b in pairs (leftbrake) do
  224.                         b.Brightness = 2
  225.                     end
  226.                 end
  227.             end
  228.             if tempright == true then
  229.                 for _,i in pairs (rightturn) do
  230.                     i.BrickColor = BrickColor.new("Neon orange")
  231.                     i.Material = "Metal"
  232.                 end
  233.                 for _,b in pairs (rightflash) do
  234.                     b.Enabled = false
  235.                 end
  236.                 for _,a in pairs (rightlight) do
  237.                     a.BrickColor = BrickColor.new("Bright red")
  238.                     a.Material = "Metal"
  239.                 end
  240.                 for _,b in pairs (rightbrake) do
  241.                     b.Brightness = 1
  242.                 end
  243.             else
  244.                 if throttle > 0 then
  245.                     for _,a in pairs (rightlight) do
  246.                         a.BrickColor = BrickColor.new("Bright red")
  247.                         a.Material = "Metal"
  248.                     end
  249.                     for _,b in pairs (rightbrake) do
  250.                         b.Brightness = 1
  251.                     end
  252.                 else
  253.                     for _,a in pairs (rightlight) do
  254.                         a.BrickColor = BrickColor.new("Really red")
  255.                         a.Material = "Neon"
  256.                     end
  257.                     for _,b in pairs (rightbrake) do
  258.                         b.Brightness = 2
  259.                     end
  260.                 end
  261.             end
  262.             wait(0.35)
  263.         until turningleft == false and turningright == false
  264.         turndebounce = false
  265.     end
  266. end
  267.  
  268. seat.ChildRemoved:connect(function(it)
  269.     if it:IsA("Weld") then
  270.         if it.Part1.Parent == Player.Character then
  271.             script.Parent.EM_Sirens.Disabled = true
  272.             script.Parent.ELS_Status.SirenStatus.Locked.Visible = true
  273.             script.Parent.ELS_Status.SirenStatus.MBOV.Visible = true
  274.             lock = true
  275.             ha=false
  276.             hd=false
  277.             hs=false
  278.             hw=false
  279.             throttle = 0
  280.             steer = 0
  281.             watdo()
  282.             script.Parent.close.Active = true
  283.             script.Parent.close.Visible = true
  284.             script.Parent.xlabel.Visible = true
  285.         end
  286.     end
  287. end)
  288. seat.ChildAdded:connect(function(it)
  289.     if it:IsA("Weld") then
  290.         if it.Part1.Parent == Player.Character then
  291.             script.Parent.EM_Sirens.Disabled = false
  292.             script.Parent.ELS_Status.SirenStatus.Locked.Visible = false
  293.             script.Parent.ELS_Status.SirenStatus.MBOV.Visible = true
  294.             lock = false
  295.             script.Parent.close.Active = false
  296.             script.Parent.close.Visible = false
  297.             script.Parent.xlabel.Visible = false
  298.         end
  299.     end
  300. end)
  301. function exiting()
  302.     lock = true--when we close the gui stop everything
  303.     steer = 0
  304.     throttle = 0
  305.     watdo()
  306.     turningleft = false
  307.     turningright = false
  308.     lightson = false
  309.     seat.exit:FireServer()
  310.     for _,i in pairs (leftturn) do
  311.         i.BrickColor = BrickColor.new("Neon orange")
  312.         i.Material = "Metal"
  313.     end
  314.     for _,a in pairs (leftlight) do
  315.         a.BrickColor = BrickColor.new("Really red")
  316.         a.Material = "Metal"
  317.     end
  318.     for _,b in pairs (leftflash) do
  319.         b.Enabled = false
  320.     end
  321.     for _,b in pairs (leftbrake) do
  322.         b.Brightness = 2
  323.     end
  324.     for _,i in pairs (rightturn) do
  325.         i.BrickColor = BrickColor.new("Neon orange")
  326.         i.Material = "Metal"
  327.     end
  328.     for _,a in pairs (rightlight) do
  329.         a.BrickColor = BrickColor.new("Really red")
  330.         a.Material = "Metal"
  331.     end
  332.     for _,b in pairs (rightflash) do
  333.         b.Enabled = false
  334.     end
  335.     for _,b in pairs (rightbrake) do
  336.         b.Brightness = 2
  337.     end
  338.     script.Parent.Parent:Destroy()--destroy the 'Car' ScreenGui
  339. end
  340.  
  341. function updatelights()
  342.     for _,i in pairs (leftbrake) do
  343.         i.Enabled = lightson
  344.     end
  345.     for _,i in pairs (rightbrake) do
  346.         i.Enabled = lightson
  347.     end
  348.     for _,i in pairs (brakelight) do
  349.         i.Enabled = lightson
  350.     end
  351.     for _,i in pairs (headlight) do
  352.         i.Enabled = lightson
  353.     end
  354.     if lightson then
  355.         script.Parent.lightimage.Image = imgassets.lightson
  356.     else
  357.         script.Parent.lightimage.Image = imgassets.lightsoff
  358.     end
  359. end
  360.  
  361. script.Parent.lights.MouseButton1Click:connect(function()
  362.     if lock then return end
  363.     lightson = not lightson
  364.     events.lights:FireServer(lightson)
  365.     if lightson then
  366.         script.Parent.lightimage.Image = imgassets.lightson
  367.     else
  368.         script.Parent.lightimage.Image = imgassets.lightsoff
  369.     end
  370. end)
  371.  
  372. function destroycar()
  373.     events.destroycar:FireServer(seat.Parent)
  374.     script.Parent.Parent:Destroy()
  375. end
  376.  
  377. script.Parent.close.MouseButton1Up:connect(exiting)
  378. Player.Character.Humanoid.Died:connect(destroycar)
  379.  
  380. game.Players.PlayerRemoving:connect(function(Playeras)
  381.     if Playeras.Name == Player.Name then
  382.         destroycar()
  383.     end
  384. end)
  385.  
  386. for _, i in pairs (seat.Parent:GetChildren()) do--populate the tables for ease of modularity. You could have 100 left wheels if you wanted.
  387.     if i.Name == "LeftWheel" then
  388.         table.insert(left,i)
  389.     elseif i.Name == "RightWheel" then
  390.         table.insert(right,i)
  391.     elseif i.Name == "Rearlight" then
  392.         table.insert(rearlight,i)
  393.     elseif i.Name == "Brakelight" then
  394.         table.insert(brakelight,i.SpotLight)
  395.     elseif i.Name == "rightturn" then
  396.         table.insert(rightturn,i)
  397.     elseif i.Name == "leftturn" then
  398.         table.insert(leftturn,i)
  399.     elseif i.Name == "leftflash" then
  400.         table.insert(leftflash,i.SpotLight)
  401.     elseif i.Name == "rightflash" then
  402.         table.insert(rightflash,i.SpotLight)
  403.     elseif i.Name == "leftlight" then
  404.         table.insert(leftlight,i)
  405.     elseif i.Name == "rightlight" then
  406.         table.insert(rightlight,i)
  407.     elseif i.Name == "Headlight" then
  408.         table.insert(headlight,i.SpotLight)
  409.     elseif i.Name == "leftbrake" then
  410.         table.insert(leftbrake,i.SpotLight)
  411.     elseif i.Name == "rightbrake" then
  412.         table.insert(rightbrake,i.SpotLight)
  413.     elseif i.Name == "revlight" then
  414.         table.insert(revlight,i.SpotLight)
  415.     end
  416. end
  417.  
  418. for _,l in pairs (left) do
  419.     l.BottomParamA = 0
  420.     l.BottomParamB = 0
  421. end
  422. for _,r in pairs (right) do
  423.     r.BottomParamA = 0
  424.     r.BottomParamB = 0
  425. end
  426.  
  427. function watdo()
  428.     seat.Parent.LeftMotor.DesiredAngle = math.rad(throttle < 0 and 40* steer or 40*steer/gear^0.5)
  429.     seat.Parent.RightMotor.DesiredAngle = math.rad(throttle < 0 and 40* steer or 40*steer/gear^0.5)
  430.     for _,l in pairs (left) do--I do it this way so that it's not searching the model every time an input happens
  431.         if throttle ~= -1 then
  432.             l.BottomParamA = (.1/gear)
  433.             l.BottomParamB = (.5*gear+steer*gear/30)*throttle
  434.         else
  435.             l.BottomParamA = -.01
  436.             l.BottomParamB = -.5-steer/20
  437.         end
  438.     end
  439.     for _,r in pairs (right) do
  440.         if throttle ~= -1 then
  441.             r.BottomParamA = -(.1/gear)
  442.             r.BottomParamB = -(.5*gear-steer*gear/30)*throttle
  443.         else
  444.             r.BottomParamA = .01
  445.             r.BottomParamB = .5-steer/20
  446.         end
  447.     end
  448.     if throttle < 1 then
  449.         for _,g in pairs (rearlight) do
  450.             g.BrickColor = BrickColor.new("Really red")
  451.             g.Material = "Neon"
  452.         end
  453.         for _,b in pairs (brakelight) do
  454.             b.Brightness = 2
  455.         end
  456.         if turningleft == false then
  457.             for _,a in pairs (leftlight) do
  458.                 a.BrickColor = BrickColor.new("Really red")
  459.                 a.Material = "Neon"
  460.             end
  461.             for _,b in pairs (leftbrake) do
  462.                 b.Brightness = 2
  463.             end
  464.         end
  465.         if turningright == false then
  466.             for _,a in pairs (rightlight) do
  467.                 a.BrickColor = BrickColor.new("Really red")
  468.                 a.Material = "Neon"
  469.             end
  470.             for _,b in pairs (rightbrake) do
  471.                 b.Brightness = 2
  472.             end
  473.         end
  474.     else
  475.         for _,g in pairs (rearlight) do
  476.             g.BrickColor = BrickColor.new("Bright red")
  477.             g.Material = "Metal"
  478.         end
  479.         for _,b in pairs (brakelight) do
  480.             b.Brightness = 1
  481.         end
  482.         if turningleft == false then
  483.             for _,a in pairs (leftlight) do
  484.                 a.BrickColor = BrickColor.new("Bright red")
  485.                 a.Material = "Metal"
  486.             end
  487.             for _,b in pairs (leftbrake) do
  488.                 b.Brightness = 1
  489.             end
  490.         end
  491.         if turningright == false then
  492.             for _,a in pairs (rightlight) do
  493.                 a.BrickColor = BrickColor.new("Bright red")
  494.                 a.Material = "Metal"
  495.             end
  496.             for _,b in pairs (rightbrake) do
  497.                 b.Brightness = 1
  498.             end
  499.         end
  500.     end
  501.     if throttle < 0 then
  502.         for _,b in pairs (revlight) do
  503.             if lightson then
  504.                 b.Parent.Material = "Neon"
  505.                 b.Enabled = true
  506.             end
  507.         end
  508.     else
  509.         for _,b in pairs (revlight) do
  510.             b.Parent.Material = "Metal"
  511.             b.Enabled = false
  512.         end
  513.     end
  514. end
  515.  
  516. Player:GetMouse().KeyDown:connect(function(key)--warning ugly button code
  517.     if lock then return end
  518.     key = string.upper(key)
  519.     if not ha and key == "A" or key == string.char(20) and not ha then
  520.         ha = true
  521.         steer = steer-1
  522.     end
  523.     if not hd and key == "D" or key == string.char(19) and not hd then
  524.         hd = true
  525.         steer = steer+1
  526.     end
  527.     if not hw and key == "W" or key == string.char(17) and not hw then
  528.         hw = true
  529.         throttle = throttle+1
  530.     end
  531.     if not hs and key == "S" or key == string.char(18) and not hs then
  532.         hs = true
  533.         throttle = throttle-1
  534.     end
  535.     if key == "Z" then
  536.         geardown()
  537.     end
  538.     if key == "X" then
  539.         gearup()
  540.     end
  541.     if key == "Q" then
  542.         turningleft = not turningleft
  543.         turn()
  544.     end
  545.     if key == "E" then
  546.         turningright = not turningright
  547.         turn()
  548.     end
  549.     watdo()
  550. end)
  551. Player:GetMouse().KeyUp:connect(function(key)
  552.     if lock then return end
  553.     key = string.upper(key)
  554.     if ha and key == "A" or key == string.char(20)and ha then
  555.         steer = steer+1
  556.         ha = false
  557.     end
  558.     if hd and key == "D" or key == string.char(19) and hd then
  559.         steer = steer-1
  560.         hd = false
  561.     end
  562.     if hw and key == "W" or key == string.char(17) and hw then
  563.         throttle = throttle-1
  564.         hw = false
  565.     end
  566.     if hs and key == "S" or key == string.char(18) and hs then
  567.         throttle = throttle+1
  568.         hs = false
  569.     end
  570.     if key == "" then
  571.         --more keys if I need them
  572.     end
  573.     watdo()
  574. end)   
  575.  
  576.  
  577.    
  578. while true do
  579.     wait(0.1)
  580.     script.Parent.Speed.Text = ("Speed: "..math.floor(seat.Velocity.Magnitude/2))
  581. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement