Advertisement
TheFakeFew

car

Sep 29th, 2024 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.28 KB | None | 0 0
  1. local owner = owner or script:FindFirstAncestorOfClass("Player")
  2. local character = owner.Character
  3. local rootpart = character.HumanoidRootPart
  4. local humanoid = character:FindFirstChildOfClass("Humanoid")
  5.  
  6. local tool = Instance.new("Tool", owner.Backpack)
  7. tool.RequiresHandle = false
  8. tool.Name = "car"
  9. tool.CanBeDropped = false
  10. script.Parent = tool
  11.  
  12. local hoverheight = 4
  13.  
  14. local att = Instance.new("Attachment")
  15. att.CFrame = CFrame.new(0, -.5 - hoverheight, 0)
  16.  
  17. local smoke = Instance.new("Smoke")
  18. smoke.Opacity = 0
  19. smoke.Size = .3
  20.  
  21. local carrunning = Instance.new("Sound")
  22. carrunning.SoundId = "http://www.roblox.com/asset/?id=391824568"
  23. carrunning.Volume = 1
  24. carrunning.Looped = true
  25.  
  26. local carstarting = Instance.new("Sound")
  27. carstarting.SoundId = "rbxassetid://912961304"
  28. carstarting.Volume = 2
  29.  
  30. local equipped = false
  31. tool.Equipped:Connect(function()
  32.     equipped = true
  33.     att.Parent = rootpart
  34.     smoke.Parent = att
  35.     carrunning.Parent = rootpart
  36.     carstarting.Parent = rootpart
  37.     carstarting:Play()
  38.     carrunning:Play()
  39. end)
  40. tool.Unequipped:Connect(function()
  41.     equipped = false
  42.     att.Parent = nil
  43.     carstarting.Parent = nil
  44.     carrunning.Parent = nil
  45.     smoke.Parent = nil
  46.     carrunning:Stop()
  47. end)
  48.  
  49. local param = RaycastParams.new()
  50. param.FilterDescendantsInstances = {character}
  51. local overlap = OverlapParams.new()
  52. overlap.FilterDescendantsInstances = {character}
  53.  
  54. local crashids = {"rbxassetid://135850769", "rbxassetid://152274149", "rbxassetid://152273920", "rbxassetid://152273933"}
  55. local i = 0
  56.  
  57. game:GetService("RunService").Stepped:Connect(function()
  58.     if(equipped)then
  59.         i += 1
  60.  
  61.         for i, v in next, character:GetDescendants() do
  62.             if(v:IsA("BasePart"))then
  63.                 v.Anchored = false
  64.             end
  65.         end
  66.  
  67.         local onground = workspace:Raycast(rootpart.Position, Vector3.yAxis*-hoverheight, param)
  68.         local mag = rootpart.AssemblyLinearVelocity.Magnitude
  69.         if(mag >= 30 and mag <= 80 and i%3 == 0)then
  70.             local parts = workspace:GetPartBoundsInRadius(rootpart.Position, rootpart.Size.Y*5, overlap)
  71.             local damaged = {}
  72.             for i, v in next, parts do
  73.                 if(v:FindFirstAncestorOfClass("Model") and v:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid") and not damaged[v:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid")])then
  74.                     damaged[v:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid")] = true
  75.                     v:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid"):TakeDamage(mag/10)
  76. local s = Instance.new("Sound", v)
  77.                     s.Volume = 1+mag/5
  78.                     s.SoundId = crashids[math.random(#crashids)]
  79.                     s:Play()
  80.                     task.delay(3, pcall, game.Destroy, s)
  81.                 end
  82.             end
  83.         elseif(mag >= 80 and i%3 == 0)then
  84.             local parts = workspace:GetPartBoundsInRadius(rootpart.Position, rootpart.Size.Y*5, overlap)
  85.             for i, v in next, parts do
  86.                 if(v.Name:lower() ~= "base" and v.Name:lower() ~= "baseplate")then
  87.                     pcall(function()
  88.                         v.Anchored = false
  89.                         v:BreakJoints()
  90.                         local vel = Instance.new("BodyVelocity", v)
  91.                         vel.maxForce = Vector3.one*math.huge
  92.                         vel.velocity = -CFrame.new(v.Position, rootpart.Position).lookVector*(mag/2)
  93.                         game:GetService("Debris"):AddItem(vel, .1)
  94.                         local s = Instance.new("Sound", v)
  95.                         s.Volume = 1+mag/5
  96.                         s.SoundId = crashids[math.random(#crashids)]
  97.                         s:Play()
  98.                         task.delay(3, pcall, game.Destroy, s)
  99.                     end)
  100.                 end
  101.             end
  102.         end
  103.         if(onground)then
  104.             smoke.Opacity = math.min(1, math.abs(mag/60)) - .3
  105.         end
  106.        
  107.         carrunning.Pitch = .2+mag/60
  108.     end
  109. end)
  110.  
  111. NLS([[
  112. local owner = owner or script:FindFirstAncestorOfClass("Player")
  113. local character = owner.Character
  114. local rootpart = character.HumanoidRootPart
  115. local humanoid = character:FindFirstChildOfClass("Humanoid")
  116. humanoid.UseJumpPower = true
  117.  
  118. local hover = Instance.new("BodyPosition")
  119. hover.MaxForce = Vector3.one*math.huge
  120. local gyro = Instance.new("BodyGyro")
  121. gyro.MaxTorque = Vector3.one*math.huge
  122. gyro.P = 1e4
  123.  
  124. local tool = script.Parent.Parent
  125. local rot = 0
  126. local velocity = Vector3.zero
  127. local rotdiff = 0
  128. local rotdiffx = 0
  129.  
  130. local equipped = false
  131. tool.Equipped:Connect(function()
  132.     equipped = true
  133.    
  134.     rot = rootpart.Orientation.Y
  135.     gyro.Parent = rootpart
  136.     humanoid.JumpPower = 0
  137. end)
  138. tool.Unequipped:Connect(function()
  139.     equipped = false
  140.    
  141.     gyro.Parent = nil
  142.     hover.Parent = nil
  143.  
  144.     humanoid.JumpPower = 50
  145.     humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
  146.    
  147.     velocity = Vector3.zero
  148.     rotdiff = 0
  149.     rotdiffx = 0
  150.  
  151.     humanoid.Sit = false
  152. end)
  153.  
  154. local param = RaycastParams.new()
  155. param.FilterDescendantsInstances = {character}
  156.  
  157. local uis = game:GetService("UserInputService")
  158. local moving = false
  159.  
  160. local hoverheight = rootpart.Size.Y*2
  161. local rotspeed = 5
  162. local maxvel = math.huge
  163. local movespeed = 5
  164. local jitter = hoverheight/4
  165. local jump = 30
  166.  
  167. local function clampvector(vec, maxx, maxy, maxz)
  168.     return Vector3.new(math.clamp(vec.X, -maxx, maxx), math.clamp(vec.Y, -maxy, maxy), math.clamp(vec.Z, -maxz, maxz))
  169. end
  170.  
  171. local rotating = false
  172. local jumping = false
  173.  
  174. game:GetService("RunService").Stepped:Connect(function(t, dt)
  175.     if(equipped)then
  176.         for i, v in next, character:GetDescendants() do
  177.             if(v:IsA("BasePart"))then
  178.                 v.Anchored = false
  179.             end
  180.         end
  181.         local onground = workspace:Raycast(rootpart.Position, Vector3.yAxis*-hoverheight, param)
  182.    
  183.         if(not game:GetService("UserInputService"):GetFocusedTextBox())then
  184.             if(uis:IsKeyDown(Enum.KeyCode.W))then
  185.                 velocity = velocity - (Vector3.zAxis*movespeed)
  186.             end
  187.             if(uis:IsKeyDown(Enum.KeyCode.S))then
  188.                 velocity = velocity + (Vector3.zAxis*movespeed)
  189.             end
  190.             if(uis:IsKeyDown(Enum.KeyCode.A))then
  191.                 rot = rot + (rotspeed*(60*dt))
  192.                 rotdiff = rotdiff + 1
  193.             end
  194.             if(uis:IsKeyDown(Enum.KeyCode.D))then
  195.                 rot = rot - (rotspeed*(60*dt))
  196.                 rotdiff = rotdiff - 1
  197.             end
  198.            
  199.             if(uis:IsKeyDown(Enum.KeyCode.Space))then
  200.                 if(onground)then
  201.                     velocity = velocity + (Vector3.yAxis*(jump*60))
  202.                     jumping = true
  203.                 end
  204.             end
  205.  
  206.             if(not uis:IsKeyDown(Enum.KeyCode.S) and not uis:IsKeyDown(Enum.KeyCode.W))then
  207.                 moving = false
  208.             else
  209.                 moving = true
  210.             end
  211.             if(not uis:IsKeyDown(Enum.KeyCode.A) or not uis:IsKeyDown(Enum.KeyCode.D) or jumping)then
  212.                 rotating = false
  213.             else
  214.                 rotating = true
  215.             end
  216.         else
  217.             rotating = false
  218.             moving = false
  219.         end
  220.  
  221.         if(not moving)then
  222.             velocity = velocity / (1+(dt*2))
  223.         end
  224.         if(not rotating)then
  225.             rotdiff = rotdiff / (1+(dt*2))
  226.             rotdiffx = rotdiffx / (1+(dt*2))
  227.         end
  228.  
  229.         velocity = clampvector(velocity, 0, 40*maxvel, 60*maxvel)
  230.         rot = rot%360
  231.         rotdiff = math.clamp(rotdiff, -20, 20)
  232.        
  233.         if(not onground)then
  234.             rotdiffx = math.clamp(rootpart.AssemblyLinearVelocity.Y/4, -20, 20)
  235.         end
  236.        
  237.         humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, true)
  238.         humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
  239.        
  240.         humanoid.Sit = true
  241.         gyro.CFrame = CFrame.Angles(math.rad(rotdiffx), math.rad(rot), math.rad(rotdiff))
  242.        
  243.         if(onground or jumping)then
  244.             if(onground)then jumping = false end
  245.            
  246.             hover.Parent = rootpart
  247.             hover.Position = (rootpart.CFrame*CFrame.new(0,-rootpart.CFrame.Y,0)*CFrame.new((Vector3.yAxis*(onground.Position.Y+((hoverheight - jitter)+(jitter*math.cos(tick()*20)))))+(velocity/(1/dt)))).Position
  248.         else
  249.             hover.Parent = nil
  250.         end
  251.     end
  252. end)
  253. ]], script)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement