Hello,
I would need advice on the script, regarding the high jump, but where the length of the character’s jump would be affected by the length of holding the “SPACE” key
The longer I held the key, the longer the character’s jump would be.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local jumpPower = 50 -- Základní síla skoku
local maxJumpPower = 100 ---- Maximální síla skoku
local jumpChargeRate = 10 ---- Rychlost nabíjení skoku
local isChargingJump = false
local jumpCharge = 0
humanoid.AutoJump = false ---- Zakaže u postavy auto výskok
local function startChargingJump()
isChargingJump = true
jumpCharge = 0
while isChargingJump and jumpCharge < maxJumpPower do
jumpCharge = jumpCharge + jumpChargeRate
wait(0.1) -- Zpoždění pro kontrolu nabíjení skoku
end
end
local function performJump()
isChargingJump = false
local finalJumpPower = math.min(jumpPower + jumpCharge, maxJumpPower)
humanoid.JumpPower = finalJumpPower
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
startChargingJump()
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space and isChargingJump then
performJump()
end
end)
Hello, I am a bit confused but as I understand you want something like this:
local player = game.Players.LocalPlayer
local jumpPower = 50 -- Basic jump power
local maxJumpPower = 100 -- Maximum jump power
local jumpChargeRate = 10 -- Jump charge rate
local jumpChargeDelay = 0.1 -- Delay for jump charging
local isChargingJump = false
local jumpCharge = 0
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.AutoJump = false -- Disable auto jump
local function startChargingJump()
if not isChargingJump then
isChargingJump = true
jumpCharge = 0
while isChargingJump and jumpCharge < maxJumpPower do
jumpCharge = jumpCharge + jumpChargeRate
wait(jumpChargeDelay)
end
end
end
local function performJump()
isChargingJump = false
local finalJumpPower = math.min(jumpPower + jumpCharge, maxJumpPower)
humanoid.JumpPower = finalJumpPower
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
wait() -- Allow jump to initiate
humanoid.JumpPower = jumpPower -- Reset jump power
end
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
startChargingJump()
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space and isChargingJump then
performJump()
end
end)
end
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end
All you need to do is check the floor material, anyways i was bored so i made my own (not bragging just felt like it)
You can shorten it all into one function with ContextActionService and mathemathics
local contextActionService=game:GetService("ContextActionService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid= character:WaitForChild("Humanoid")
local jumpPower = 50 -- jump power
local maxJumpPower = 200 -- Maximum jump power
local jumpCharge=50 --How much force is gained each second
local jumpStart
local function jump(name,inputState,inputObject)
if humanoid.FloorMaterial==Enum.Material.Air then return end--Player is airborn
if inputState==Enum.UserInputState.Begin then--Space is pressed
jumpStart=tick()
elseif inputState==Enum.UserInputState.End then --Space is released
if not jumpStart then jumpStart=tick() end --Just in case
local Power=(tick()-jumpStart)*jumpCharge
humanoid.JumpPower=math.clamp(Power,jumpPower,maxJumpPower)
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.wait()
humanoid.JumpPower=0
end
end
contextActionService:UnbindAction("jumpAction")
contextActionService:BindAction("Jump",jump,false,Enum.KeyCode.Space)
It can be done with UserInputService but it’s gonna be slightly more annoying
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local jumpPower = 50 -- Základní síla skoku
local maxJumpPower = 100 ---- Maximální síla skoku
local jumpChargeRate = 10 ---- Rychlost nabíjení skoku
local isChargingJump = false
local jumpCharge = 0
humanoid.AutoJump = false ---- Zakaže u postavy auto výskok
local function startChargingJump()
isChargingJump = true
jumpCharge = 0
while isChargingJump and jumpCharge < maxJumpPower do
jumpCharge = jumpCharge + jumpChargeRate
wait(0.1) -- Zpoždění pro kontrolu nabíjení skoku
end
end
local function performJump()
if humanoid.FloorMaterial ~= Enum.Material.Air then
isChargingJump = false
local finalJumpPower = math.min(jumpPower + jumpCharge, maxJumpPower)
humanoid.JumpPower = finalJumpPower
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
game:GetService("UserInputService").JumpRequest:Connect(function()
startChargingJump()
end)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space and isChargingJump then
performJump()
end
end)
local player = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local jumping = false
local jumpHeight = 2 -- Adjust this value as needed
function onKeyPress(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.Space then
jumping = true
while jumping and player.Character and player.Character:FindFirstChild("Humanoid") do
local humanoid = player.Character:FindFirstChild("Humanoid")
humanoid:Move(Vector3.new(0, jumpHeight, 0))
wait(0.1)
end
end
end
function onKeyRelease(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.Space then
jumping = false
end
end
userInputService.InputBegan:Connect(onKeyPress)
userInputService.InputEnded:Connect(onKeyRelease)