Advertisement
Guest User

Roblox Dev Script "DriveSeat Fuel"

a guest
Mar 29th, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. local seat = script.Parent
  2. local mS = seat.MaxSpeed
  3. local gas = seat:WaitForChild("Gas")
  4. local gui = seat:WaitForChild("GGui")
  5. local gClone = gui:Clone()
  6. local on = false
  7. local usable = true
  8. local consume = false
  9. local consumeWhenIdel = true -- wherther or not to count idel time as using gas
  10. local refuelable = true -- whether or not it can be refueled
  11. local infiniteGas = false -- whether or not gas is needed
  12. local rateOfConsume = 1 -- Persecond of use and use when idel
  13. local extraToMove,extraRate,turning,tRate = true,2,true,.5 -- the first value is whether
  14. -- or not it cost extra gas to move (true or false) the second value is how much extra
  15. -- per second of use, turing is whether or not turing counts, and the last is the rate
  16. -- of turing (false means the same amount as extraRate)
  17. local list = script.Parent.Parent
  18. local player
  19.  
  20. if not infiniteGas then
  21.  
  22. local check = coroutine.create(function()
  23. while true do
  24. if gas.Value > 0 then
  25. seat.MaxSpeed = mS
  26. elseif gas.Value<=0 then
  27. seat.MaxSpeed = 0
  28. end
  29. gas.Changed:wait()
  30. end
  31. end)
  32. coroutine.resume(check)
  33.  
  34.  
  35. local consumeIdelGas = coroutine.create(function()
  36. while usable or refuelable do
  37. while on do
  38. if consume or consumeWhenIdel then
  39. if extraToMove then
  40. if consume == "steer" then
  41. gas.Value=gas.Value-((rateOfConsume*.1)+(tRate*.1))
  42. elseif consume == "ST" then
  43. gas.Value=gas.Value-((rateOfConsume*.1)+(tRate*.1)+(extraRate*.1))
  44. else
  45. gas.Value=gas.Value-((rateOfConsume*.1)+(extraRate*.1))
  46. end
  47. else
  48. gas.Value=gas.Value-(rateOfConsume*.1)
  49. end
  50. end
  51. wait(.1)
  52. end
  53. if gas.Value < 0 then gas.Value = 0 end
  54. wait()
  55. end
  56. end)
  57. coroutine.resume(consumeIdelGas)
  58.  
  59. local checkGas = coroutine.create(function()
  60. while true do
  61. usable = not seat.Disabled
  62. if not usable then
  63. if not refuelable then
  64. break
  65. else
  66. usable = not seat.Disabled
  67. end
  68. end
  69. seat.Changed:wait()
  70. end
  71. end)
  72. coroutine.resume(checkGas)
  73.  
  74. if extraToMove then
  75. local engine = coroutine.create(function()
  76. local moving,throttle,steer = false
  77. while true do
  78. while on do
  79. local move = seat.Changed:wait()
  80. if move == "Throttle" then
  81. throttle = not throttle
  82. end
  83. if move == "Steer" then
  84. if turning then
  85. steer = not steer
  86. end
  87. end
  88. if steer or throttle then
  89. moving = true
  90. else
  91. moving = false
  92. end
  93. if turning and tRate then
  94. if steer and not throttle then
  95. consume = "steer"
  96. elseif steer and throttle then
  97. consume = "ST"
  98. else
  99. consume = moving
  100. end
  101. else
  102. consume = moving
  103. end
  104. end
  105. if not usable and not refuelable then
  106. break
  107. end
  108. wait()
  109. end
  110. end)
  111. coroutine.resume(engine)
  112. end
  113.  
  114. function stop(weld)
  115. if weld.ClassName == "Weld" then
  116. gClone.Parent = nil
  117. on = false
  118. player = false
  119. end
  120. end
  121.  
  122. function start(weld)
  123. if weld.ClassName == "Weld" then
  124. player=game.Players:GetPlayerFromCharacter(weld.Part1.Parent)
  125. gClone.Parent = player:WaitForChild("PlayerGui")
  126. on = true
  127. end
  128. end
  129.  
  130. seat.ChildAdded:connect(start)
  131. seat.ChildRemoved:connect(stop)
  132.  
  133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement