I have tried a lot of stuff but nothing seems to work.
Please Help
I have tried a lot of stuff but nothing seems to work.
Please Help
there’s some ways to do it, but the easiest one is:
when the space bar is pressed, record the current time. when it’s released, calculate the duration by subtracting the press time from the current time. i’ll leave an example below
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local defaultJumpPower = humanoid.JumpPower
local maxJumpPower = 100
local pressTime = nil
local function onJumpRequest()
if pressTime then
local duration = tick() - pressTime
local jumpPowerIncrease = math.min(duration * 50, maxJumpPower - defaultJumpPower)
humanoid.JumpPower = defaultJumpPower + jumpPowerIncrease
task.wait(0.1)
humanoid.JumpPower = defaultJumpPower
pressTime = nil
end
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.Space then
pressTime = tick()
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space then
onJumpRequest()
end
end)
player.CharacterAdded:Connect(function(char)
humanoid = char:WaitForChild("Humanoid")
humanoid.JumpPower = defaultJumpPower
end)