Advertisement
HowToRoblox

SkydiveClient

Jan 21st, 2022
1,951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. local uis = game:GetService("UserInputService")
  2.  
  3. local animation = script.Parent:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("SkydiveAnimation"))
  4.  
  5. local startOfFall = 0
  6. local falling = false
  7.  
  8.  
  9. script.Parent.Humanoid.StateChanged:Connect(function(oldState, newState)
  10.    
  11.     if newState == Enum.HumanoidStateType.Freefall then
  12.        
  13.         falling = true
  14.        
  15.         if not animation.IsPlaying then
  16.            
  17.             startOfFall = os.time()
  18.            
  19.             animation:Play()
  20.             game.ReplicatedStorage:WaitForChild("SkydiveRE"):FireServer(true)
  21.            
  22.             local connection
  23.             connection = uis.InputBegan:Connect(function(inp, p)
  24.                
  25.                 local timeFalling = os.time() - startOfFall
  26.                
  27.                 if not p and inp.KeyCode == Enum.KeyCode.Space and timeFalling > 1 and falling then
  28.                    
  29.                     falling = false
  30.                    
  31.                     game.ReplicatedStorage.SkydiveRE:FireServer("parachute")
  32.                    
  33.                     connection:Disconnect()
  34.                 end
  35.             end)
  36.         end
  37.    
  38.     else
  39.        
  40.         falling = false
  41.        
  42.         animation:Stop()
  43.         game.ReplicatedStorage:WaitForChild("SkydiveRE"):FireServer(false)
  44.        
  45.         if newState == Enum.HumanoidStateType.Landed then
  46.            
  47.             game.ReplicatedStorage:WaitForChild("SkydiveRE"):FireServer("landed")
  48.         end
  49.     end
  50. end)
  51.  
  52.  
  53. game:GetService("RunService").Heartbeat:Connect(function()
  54.    
  55.     if falling then
  56.        
  57.         local rayResult = workspace:Raycast(script.Parent.HumanoidRootPart.Position, script.Parent.HumanoidRootPart.Position - Vector3.new(0, 200, 0))
  58.        
  59.         if rayResult and rayResult.Instance.CanCollide then
  60.            
  61.             falling = false
  62.  
  63.             game.ReplicatedStorage.SkydiveRE:FireServer("parachute")
  64.         end
  65.     end
  66. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement