Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wait();
- local MaxFlySpeed = 2 -- change this as needed
- local UIS = game:GetService("UserInputService")
- local LocalPlayer = game:GetService("Players").LocalPlayer
- local Torso = (LocalPlayer.Character and LocalPlayer.Character:WaitForChild("Torso"))
- local Mouse = LocalPlayer:GetMouse()
- local Tool = Instance.new("Tool")
- Tool.RequiresHandle = false
- Tool.Name = "Fly tool"
- assert(Torso.ClassName == "Part", "Yikes! Torso is not a part.")
- local ToolUtils do
- ToolUtils = {
- --// Setup Vars
- Enabled = false,
- WindowFocused = true,
- Keys = {},
- InternalVars = {
- FlyForward = 0,
- FlyBackward = 0
- }
- }
- end
- local ToolEvents do
- Tool.Equipped:connect(function(Mouse)
- ToolUtils.Enabled = true
- Torso.Anchored = true
- end)
- Tool.Unequipped:connect(function(...)
- ToolUtils.Enabled = false
- Torso.Anchored = false
- end)
- UIS.InputBegan:connect(function(input, processedEvent)
- ToolUtils.Keys[input.KeyCode] = true
- end)
- UIS.InputEnded:connect(function(input, processedEvent)
- ToolUtils.Keys[input.KeyCode] = nil
- end)
- UIS.WindowFocusReleased:connect(function()
- ToolUtils.WindowFocused = false
- end)
- UIS.WindowFocused:connect(function()
- ToolUtils.WindowFocused = true
- end)
- end
- --// Main Event
- game:GetService("RunService").RenderStepped:connect(function(...)
- if ToolUtils.WindowFocused and ToolUtils.Enabled then
- if ToolUtils.Keys[Enum.KeyCode.W] then
- if ToolUtils.InternalVars.FlyForward < MaxFlySpeed then
- ToolUtils.InternalVars.FlyForward = ToolUtils.InternalVars.FlyForward + 0.1
- end
- else
- ToolUtils.InternalVars.FlyForward = ToolUtils.InternalVars.FlyForward * 0.9
- end
- if ToolUtils.Keys[Enum.KeyCode.S] then
- if ToolUtils.InternalVars.FlyBackward < MaxFlySpeed then
- ToolUtils.InternalVars.FlyBackward = ToolUtils.InternalVars.FlyBackward + 0.1
- end
- else
- ToolUtils.InternalVars.FlyBackward = ToolUtils.InternalVars.FlyBackward * 0.9
- end
- local Camera = workspace.CurrentCamera
- Torso.CFrame = Torso.CFrame:lerp(
- CFrame.new(Torso.Position, Camera.CFrame.p)
- * CFrame.Angles(0, math.rad(180), 0)
- * CFrame.new(0, 0, -(ToolUtils.InternalVars.FlyForward - ToolUtils.InternalVars.FlyBackward))
- * CFrame.Angles(-(math.rad(10 * (ToolUtils.InternalVars.FlyForward / MaxFlySpeed)) - math.rad(10 * (ToolUtils.InternalVars.FlyBackward / MaxFlySpeed))), 0, 0)
- , 0.9)
- end
- end)
- Tool.Parent = LocalPlayer:findFirstChild("Backpack") or Instance.new("Backpack", LocalPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement