Hey there! I’m trying to make a script where you go higher if you keep holding the jump key after you jump, but it’s not working as I want it to. It just leaves me stuck in the air. Does it have to do with my velocity script?
Jump script (local, StarterCharacterScripts):
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local jumpPower = 5
local maxJumpTime = 10
local minJumpHeight = 7.2
local canJump = true
local canAscend = false
humanoid.JumpHeight = minJumpHeight
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
userInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space and humanoid.FloorMaterial ~= Enum.Material.Air and canJump then
canJump = false
repeat
runService.RenderStepped:Wait()
local ray = workspace:Raycast(humanoid.RootPart.Position+Vector3.new(0,-2.99,0), Vector3.new(0,-.01,0), params)
until not ray
print("'' Airborne ''")
canAscend = true
task.spawn(function()
local att = Instance.new("Attachment", humanoid.RootPart)
local velocity = Instance.new("LinearVelocity")
velocity.Enabled = true
velocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
velocity.MaxAxesForce = Vector3.new(0,1,0)*math.huge
velocity.VectorVelocity = Vector3.new(0,humanoid.RootPart.AssemblyLinearVelocity.Y+jumpPower,0)
velocity.Attachment0 = att
velocity.Parent = att
local startTime = tick()
local elapsed = tick() - startTime
repeat
elapsed = tick() - startTime
runService.RenderStepped:Wait()
--print(lv.VectorVelocity)
until not canAscend or elapsed >= maxJumpTime
print("-- Done --")
att:Destroy()
end)
repeat
runService.RenderStepped:Wait()
local ray = workspace:Raycast(humanoid.RootPart.Position+Vector3.new(0,-2.99,0), Vector3.new(0,-.01,0), params)
until ray
print("__ Grounded __")
canJump = true
canAscend = false
end
end)
userInputService.InputEnded:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space and humanoid.FloorMaterial == Enum.Material.Air and not canJump then
canAscend = false
end
end)
Velocity script (local, StarterCharacterScripts):
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local statFolder = player:WaitForChild("Stats")
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local cam = workspace.CurrentCamera
character:WaitForChild("HumanoidRootPart")
local attachment = Instance.new("Attachment", humanoid.RootPart)
attachment.Name = "VelocityAttachment"
local velocity = Instance.new("LinearVelocity")
velocity.Enabled = false
velocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
velocity.MaxForce = Vector3.new(1,0,1)*math.huge
velocity.VectorVelocity = Vector3.new(1,0,1)*((humanoid.RootPart.AssemblyLinearVelocity*Vector3.new(1,0,1)).Magnitude)
velocity.Attachment0 = attachment
velocity.Parent = attachment
humanoid.Changed:Connect(function()
if humanoid.FloorMaterial == Enum.Material.Air and velocity.Enabled == false then
velocity.Enabled = true
elseif humanoid.FloorMaterial ~= Enum.Material.Air and velocity.Enabled == true then
velocity.Enabled = false
end
end)
runService.RenderStepped:Connect(function()
velocity.VectorVelocity = Vector3.new(humanoid.RootPart.AssemblyLinearVelocity.X, 0, humanoid.RootPart.AssemblyLinearVelocity.Z)+(humanoid.MoveDirection)/2
end)
Why is this happening? Any help is appreciated!