theCJarmy7

Gravity thing

Jun 10th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local char = player.Character or player.CharacterAdded:Wait()
  3.  
  4. local mouse = player:GetMouse()
  5.  
  6.  
  7. function toggleGravityForModel(model,off)
  8.     for i,v in pairs(model:GetDescendants()) do
  9.         if v:IsA("BasePart") and off then
  10.             local f = Instance.new("BodyForce")
  11.             f.Name = "GravityThing"
  12.             f.Force = Vector3.new(0, game.Workspace.Gravity * v:GetMass(),0)
  13.             if not v:FindFirstChild("GravityThing") then
  14.                 f.Parent = v
  15.             else
  16.                 f:Destroy()
  17.                 break
  18.             end
  19.         elseif not off and v:IsA("BasePart") and v:FindFirstChild("GravityThing") then
  20.             v:FindFirstChild("GravityThing"):Destroy()
  21.         end
  22.     end
  23. end
  24.  
  25.  
  26.  
  27. mouse.Button1Down:Connect(function()
  28.     toggleGravityForModel(char,true)
  29. end)
  30.  
  31. mouse.Button2Down:Connect(function()
  32.     toggleGravityForModel(char,false)
  33. end)
Advertisement
Add Comment
Please, Sign In to add comment