I need help scripting a flight script

Hi, i am a begginer scripter and in the making of a game i need to make a fly gui or a fly tool, both works, but i don’t have much knolege to make it and i can’t find a youtube tutorial for this, usually all the tutorials are Keybind flight.

Help is appreciated if you can help me it would be great, i have all the time to wait. (not quite but either way i will wait because i don’t have other options)

Just a reminder, it’s not a Keybind or :fly script it’s simply a TextButton that when you press you fly or a tool that when activated will make you fly.

The way of flight doesn’t matter, if it’s following the mouse, W,A,S,D or clicking, i just need the script.

If you don’t want or can’t make an entire script (wich i understand) you don’t need to, any help is good.

Thanks!

Basically, you would need a BodyVelocity for it.
It should be a local script.

Edit: Making a Script for you, one second.

Ok i’ll be waiting, thank you so much

1 Like

I use something like that:

local runService = game:GetService("RunService")
local GuiButton = script.Parent
local toggle = false
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local animation = script:FindFirstChild("Animation") or script:WaitForChild("Animation")
local animationTrack = humanoid:LoadAnimation(animation)

GuiButton.MouseButton1Down:Connect(function()
		if toggle == false then
			toggle = true
			BV = Instance.new("BodyVelocity", player.Character.HumanoidRootPart)
			BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			animationTrack.Looped = true
			animationTrack.Name = "FlyAnimation"
			animationTrack:Play()
			local function UpdateFly()
				BV.Velocity = player:GetMouse().Hit.LookVector * 30
				player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position + player:GetMouse().Hit.LookVector)
			end
			-- Bind the UpdateFly() method
			runService:BindToRenderStep("UpdateFly", Enum.RenderPriority.Camera.Value - 1, UpdateFly)
		-- if already flying, disable fly
		elseif toggle == true then
			-- toggle off
			toggle = false
			-- Unbind!
			runService:UnbindFromRenderStep("UpdateFly")
			--Stop the animation
			animationTrack:Stop()
			-- destroy the BodyVelocity
			if BV ~= nil then
				BV:Destroy()
		end
	end
end)

The parent should be your GuiButton and it should have an Animation Child called Animation. The animationId should be defined.
This should give you an idea.

2 Likes

Also, you could change the Text of the GuiButton after the if toggle == false then and change it back after the elseif toggle == true then

1 Like

This would basically follow the mouse.

1 Like

Actually, error in line 6, " [Humanoid is not a valid member of Model]"

Try this

local runService = game:GetService("RunService")
local GuiButton = script.Parent
local toggle = false
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChild("Humanoid") or character:WaitForChild("Humanoid")
local animation = script:FindFirstChild("Animation") or script:WaitForChild("Animation")
local animationTrack = humanoid:LoadAnimation(animation)

GuiButton.MouseButton1Down:Connect(function()
		if toggle == false then
			toggle = true
			BV = Instance.new("BodyVelocity", player.Character.HumanoidRootPart)
			BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			animationTrack.Looped = true
			animationTrack.Name = "FlyAnimation"
			animationTrack:Play()
			local function UpdateFly()
				BV.Velocity = player:GetMouse().Hit.LookVector * 30
				player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position + player:GetMouse().Hit.LookVector)
			end
			-- Bind the UpdateFly() method
			runService:BindToRenderStep("UpdateFly", Enum.RenderPriority.Camera.Value - 1, UpdateFly)
		-- if already flying, disable fly
		elseif toggle == true then
			-- toggle off
			toggle = false
			-- Unbind!
			runService:UnbindFromRenderStep("UpdateFly")
			--Stop the animation
			animationTrack:Stop()
			-- destroy the BodyVelocity
			if BV ~= nil then
				BV:Destroy()
		end
	end
end)
4 Likes