Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local uis = game:GetService("UserInputService")
- local animation = script.Parent:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("SkydiveAnimation"))
- local startOfFall = 0
- local falling = false
- script.Parent.Humanoid.StateChanged:Connect(function(oldState, newState)
- if newState == Enum.HumanoidStateType.Freefall then
- falling = true
- if not animation.IsPlaying then
- startOfFall = os.time()
- animation:Play()
- game.ReplicatedStorage:WaitForChild("SkydiveRE"):FireServer(true)
- local connection
- connection = uis.InputBegan:Connect(function(inp, p)
- local timeFalling = os.time() - startOfFall
- if not p and inp.KeyCode == Enum.KeyCode.Space and timeFalling > 1 and falling then
- falling = false
- game.ReplicatedStorage.SkydiveRE:FireServer("parachute")
- connection:Disconnect()
- end
- end)
- end
- else
- falling = false
- animation:Stop()
- game.ReplicatedStorage:WaitForChild("SkydiveRE"):FireServer(false)
- if newState == Enum.HumanoidStateType.Landed then
- game.ReplicatedStorage:WaitForChild("SkydiveRE"):FireServer("landed")
- end
- end
- end)
- game:GetService("RunService").Heartbeat:Connect(function()
- if falling then
- local rayResult = workspace:Raycast(script.Parent.HumanoidRootPart.Position, script.Parent.HumanoidRootPart.Position - Vector3.new(0, 200, 0))
- if rayResult and rayResult.Instance.CanCollide then
- falling = false
- game.ReplicatedStorage.SkydiveRE:FireServer("parachute")
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement