Hello, I have an issue with my jumping script: when I land, I get flung away. I want the force to be applied so that the player remains stationary for a moment after landing.
Here is a clip to clarify:
Here is the code, If needed:
UserInputService.InputBegan:Connect(function(Input, GPE)
if GPE then
return
end
Humanoid.Running:Connect(function(Speed)
if Input.KeyCode == Enum.KeyCode.Space and not Player:GetAttribute("Jumping") and Player:GetAttribute("Running") and Speed >= 20 then
HumanoidRootPart:ApplyImpulse(Character.PrimaryPart.CFrame.LookVector * 750)
Humanoid.StateChanged:Connect(function(State)
if State == Enum.HumanoidStateType.Landed then
print(Player.Name.." has landed.")
Humanoid.WalkSpeed = 0
task.wait(1)
Humanoid.WalkSpeed = WALKSPEED_DEFAULT
end
end)
end
end)
end)
Idk but are you trying to extend the jump forward, like a leap?
If so, once they landed anchor the Root and reset the AssemblyVelocity.
Also, 750 is a crazy number, and yeah you will fly far far.
:ApplyImpulse literally applies velocity to an object, WalkSpeed will not affect this as the velocity of the player itself is not equal to the WalkSpeed
What you could do is set the AssemblyLinearVelocity to vector.zero after the player lands in order to make them “not get flung”
You also seem to be impulsing the player forwards instead of upwards
and your script also has severe memory leaks
this script has a few issues the biggest one being the nested events that are never disconnected. This will build up really fast and cause serious issues.
I think you are overcomplicating things so i wrote this script for you.
Now i’m not exactly sure what you’re trying to do but what this script does it when you jump it leaps you forwards and when you land it gets rid of your velocity making sure you’re standing still when you land which i think is what you’re trying to do.
(LocalScript in StarterCharacterScripts)
local UserInputService = game:GetService("UserInputService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
UserInputService.JumpRequest:Connect(function()
HumanoidRootPart:ApplyImpulse(Character.PrimaryPart.CFrame.LookVector * 750)
end)
Humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero
end
end)