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.
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.
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)