I’m trying to figure out how to make a jump were you have to hold down the jump button and if you hold it down for a long time and release you jump higher depending on how long you hold it down. I can’t find anything like this and I don’t know if its too difficult or not. please help!
Im not very great when it comes to Input but try this:
UIS = game:GetService("UserInputService")
Plr = game.Players.LocalPlayer
Char = Plr.Character or Plr.CharacterAdded:Wait()
Humanoid = Char:FindFirstChild("Humanoid")
IsActive = false
JumpMultiplier = 1
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Space then
IsActive = true
end
end)
UIS.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Space then
IsActive = false
Char.PrimaryPart:ApplyImpulse(Vector3.new(0,Humanoid.JumpPower * JumpMultiplier,0))
end
end)
while IsActive == true do
wait(1)
JumpMultiplier += .1
end
-- You can disable jumping if you want.
local Clock = os.clock()
local UIS = game:GetService("UserInputService")
local StartTime = os.clock() - Clock
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
StartTime = os.clock() - Clock
end
end)
UIS.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Space then
local EndTime = os.clock() - Clock
local JumpPower= EndTime - StartTime
game.Players.LocalPlayer.Character.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0,JumpPower * 20,0) -- Change the multiplier for your use.
end
end)
Here’s a LocalScript you can place into StarterCharacterScripts and play with the numbers.
local ContextActionService = game:GetService("ContextActionService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local jumpHeight = humanoid.JumpHeight
local holdTime = 0
local function onJump(name, state, input)
if state == Enum.UserInputState.Begin then
holdTime = os.clock()
elseif humanoid.FloorMaterial ~= Enum.Material.Air then
holdTime = math.min(os.clock() - holdTime + 0.5, 1.0)
humanoid.Jump = true
humanoid.JumpHeight = jumpHeight * holdTime
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
return Enum.ContextActionResult.Sink
end
ContextActionService:BindAction("jump", onJump, false, Enum.PlayerActions.CharacterJump)
This works well thank you for your help
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.