module.abilites['DoubleJump'] = function(player:Player)
local char = player.Character
-- instances
local root = char.PrimaryPart
local rootAttach = root:FindFirstChild('RootAttachment')
local hum = char:FindFirstChildOfClass('Humanoid')
-- set values of hum
hum.WalkSpeed = 0
-- double jump
local velocity:LinearVelocity
if root:FindFirstChildOfClass('LinearVelocity') then
root:FindFirstChildOfClass('LinearVelocity'):Destroy()
end
velocity = Instance.new('LinearVelocity')
velocity.Attachment0 = rootAttach
velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
velocity.MaxForce = math.huge
velocity.VectorVelocity = Vector3.new(0,50,-30)
velocity.Parent = root
wait(0.5)
repeat
velocity.VectorVelocity -= Vector3.new(0,10,0)
task.wait(0.1)
until velocity.VectorVelocity.Y == -65
repeat
task.wait()
until hum.FloorMaterial.Name ~= 'Air'
velocity:Destroy()
return
end
Basically this function makes them go up and then down, Im pretty sure the reason it happens is caused by the linear velocity pushing the player into the ground.
(LinearVelocity | Documentation - Roblox Creator Hub)
The documentation says it applies forces to maintain a constant linear velocity. It likely causes issues because it can’t maintain the velocity if the player is grounded. Like this image recommends, you should probably set AssemblyLinearVelocity and you also won’t have to deal with the LinearVelocity objects.
Ok I tried it, this happened, which I dont think is normal sooooo.
Heres my modified code
module.abilites['DoubleJump'] = function(player:Player)
local char = player.Character
-- instances
local root = char.PrimaryPart
local rootAttach = root:FindFirstChild('RootAttachment')
local hum = char:FindFirstChildOfClass('Humanoid')
-- set values of hum
hum.WalkSpeed = 0
-- double jump
local velocity:LinearVelocity
if root:FindFirstChildOfClass('LinearVelocity') then
root:FindFirstChildOfClass('LinearVelocity'):Destroy()
end
root.AssemblyLinearVelocity = Vector3.new(0,50,-30)
wait(0.5)
repeat
root.AssemblyLinearVelocity -= Vector3.new(0,10,0)
task.wait(0.1)
until root.AssemblyLinearVelocity.Y == -65
repeat
task.wait()
until hum.FloorMaterial.Name ~= 'Air'
--velocity:Destroy()
return
end
You’re manually decreasing the Y velocity of the HRP for gravity. You don’t need to adjust this because roblox automatically handles it. The assembly linear velocity IS the current velocity of that object, so you are applying additional gravity (roblox automatically applies gravity and updates assembly linear velocity). This causes your character to be pushed into the ground even when you’re not jumping.
In the gravity you added in issue #1, you’re waiting until the velocity’s Y component is exactly equal to -65, which is nearly impossible to fulfill with time steps of 0.1, even with the velocity being automatically updated. More than that, it would probably never reach that velocity anyways because the player will probably hit the ground under them faster than they can get to -65 Y velocity. This is the second part that causes your character to be pushed into the ground after you stop jumping.
In the way you change the assembly linear velocity initially in the function, you are setting -30 for Z velocity. This probably isn’t what you want because AssemblyLinearVelocity is in global space, not object space, so it moves your character on the global Z axis, which probably isn’t intentional. You can do CFrame * Vector3 to get the Vector3 translated from object to global space.
(CFrame | Documentation - Roblox Creator Hub)
In async functions like this, you should make sure that you don’t have unwanted overlapping behavior. If you jump and, before the wait(0.5) finishes, you jump again, you will have multiple changes to your velocity which can lead to choppy and undesirable behavior.