Im working on a script that puts me in the air if I click my mouse and when I hold the mouse button down I can move around in the air and when I let go it stops.
The problem is when I release the button too early I just stay in the air and I’m just stuck there
I tried doing else if and other measures to make it not do it but it doesn’t work and even did true or false statements just can’t get it to work.
local tool = script.Parent
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local player = game:GetService("Players").LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
--Variables--
local Enabled = true
local ButtonDown = false
local Key = nil
local Rise = nil
local Usable = false
--------------------------------
tool.Equipped:Connect(function()
Usable = true
end)
tool.Unequipped:Connect(function()
Usable = false
end)
--------------------------------
UIS.InputBegan:Connect(function(input,gp)
if gp then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and Usable == true then
local Jump = Character.HumanoidRootPart.position + Vector3.new(0,20,0)
Rise = true
local BP = Instance.new("BodyPosition", Character.HumanoidRootPart)
BP.Position = Jump
BP.MaxForce = Vector3.one * 999999
BP.D = 200
BP.P = 800
if Jump == Jump then
task.wait()
Rise = false
end
if Rise == false then
BP:Destroy()
end
end
end)
UIS.InputBegan:Connect(function(input,gp)
if gp then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and Usable == true and Enabled == true then
task.wait(0.5)
ButtonDown = true
Key = "Click"
while ButtonDown == true do
local Position = mouse.Hit.Position
Character.HumanoidRootPart.Anchored = true
Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.Position, Position)
RS.Heartbeat:Wait()
end
task.wait()
player.Character.HumanoidRootPart.Anchored = false
Enabled = true
end
end)
UIS.InputEnded:Connect(function(input, gp)
if gp then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and Usable == true and Key == "Click" then
ButtonDown = false
Key = nil
Rise = nil
end
end)