How to make jump thing work

I want it to be where if you have W pressed or are moving forwards at the time of jumping you have a force applied onto you to go forwards. This is supposed to preserve momentum. I’m not sure how I would do left and right prob using right and left vectors but rn its not important. My issue is it’s not being deleted when I land! And the next time I jump it’s faster for some reason. I think the former would fix this anyway. Plus idk how to make it so you don’t change direction when you turn maybe using the RelitiveTo setting but idk how that works so please help. The normal stuff is for later don’t worry.

local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local normID = mouse.TargetSurface
local normal = Vector3.FromNormalId(normID)
local char = plr.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local att = hrp.RootAttachment
local UIS = game:GetService("UserInputService")
local hum = char:WaitForChild("Humanoid")


UIS.InputBegan:Connect(function(input, done)
	if input.KeyCode == Enum.KeyCode.Space then
		local force = Instance.new("VectorForce")
		force.Parent = att
		force.Attachment0 = att
		force.Force = Vector3.new(0,0,-10000)
		force.ApplyAtCenterOfMass = true
		force.Name = force
		force.Enabled = true
		local state = hum:GetState()
		if state == Enum.HumanoidStateType.Landed then
			force:Destroy()
		end
	end
end)
1 Like

Perhaps the reason the force isn’t being destroyed is that you’re checking if the player landed right as they start jumping. Instead, set up a Humanoid.StateChanged event and insert the Humanoid landed state condition in there. Also make sure to check if the force exists before you destroy it, as not doing so can lead to an error in some cases (like when the player falls from a height without pressing space). For efficiency, you can also connect/disconnect the event when the jump occurs and finishes.

1 Like