Ok, so I’m trying to make a jump script where the jump height depends on how long you hold space.
But there are 2 issues. If you spam space while in air, you kind of glide in the air and I don’t want the inputended function to run if you are falling because it looks unnatural.
How can I achieve this?
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local power = 0
local keyDown = false
UserInputService.InputBegan:Connect(function(key)
if (key.KeyCode == Enum.KeyCode.Space) then
keyDown = true -- set keydown to true
power = 0 -- set power back to 0
while (keyDown) do -- while keydown
wait()
power = power + 1-- increase power
end
end
end)
UserInputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space then
keyDown = false
character.HumanoidRootPart.Velocity = Vector3.new(
character.HumanoidRootPart.Velocity.X,
character.HumanoidRootPart.CFrame.UpVector * power, -- and boom, jumps as high as you held the key down for
character.HumanoidRootPart.Velocity.Z
)
end
end)