Why is body force sometimes bug and be unreliable?

I’m trying to make it so that the player jumps in the air with a force then it gets deleted after so it cancels.
But, when some of my friends try the game, sometimes they don’t get pushed up and jump up very little. Sometimes they get jumped higher than usual. Why is body force so unreliable, is it just because it is unreliable or because the player is laggy or im doing something wrong? I want it to go up a normal amount and thats all, if there are alternatives you can tell me too.

BodyForce script (SERVER SIDE FROM REMOTE EVENT):

local bodyforce = Instance.new("BodyForce", player.Character.HumanoidRootPart)
			bodyforce.Force = Vector3.new(0,4200,0)
			player.Character.Humanoid.Jump = true
2 Likes

That’s always an issue with velocities. Try adjusting the P and D properties.

2 Likes

I dont get what you mean, can you explain more and what that does and what it will do?

2 Likes

I adjusted the bodyforce.Force already though

2 Likes

The P value determines how aggressive the force is applied. Try setting that to a high number.

2 Likes

Can you give me an example, and will it fix my issue???

2 Likes

Instead of trying to get an example why don’t you…

External Media
3 Likes

I’m confused on how to change the P, and what to make the bodyforce.Force value or P value.

2 Likes

I got an error: P is not a valid member of BodyForce “Workspace.lilzy7.HumanoidRootPart.BodyForce”

2 Likes

You should have looked into the API reference next time:

Apparently, we have some mix-up with the body movers. We’re not quite certain why the force is affects players differently but its mass difference due to accessories.

2 Likes

im still confused on what to do with P and D its errors

2 Likes

The P and D are part of a different API:
https://developer.roblox.com/en-us/articles/BodyMover

There was a mix-up and you can kindly ignore that for now on.

2 Likes

According to the BodyForce example, the player’s jump height is affected by two factors:

  1. Acceleration
  2. Mass

…which is Newton’s second law of motion, describing force.

The acceleration depends on the workspace.Gravity. The most important factor that varies between players is the mass. The mass is different for each player’s size but also sometimes accessories and the tools they are holding.

2 Likes

So what do I do to fix this bug and have players get pushed up better and the same amount?

2 Likes

For each character, you need to get the total mass. This function would help getting the total mass, since each character are models.

local function getMassFromModel(model)
	local mass = 0
	for _, object in pairs(model:GetDescendants()) do
		if object:IsA("BasePart") then
			mass += object:GetMass
		end
	end
	
	return mass
end

After that, remember Newton’s second law of motion: Multiply the mass with the workspace’s gravity and then multiply it again with an alpha with an interval between 0 to 1, depending on how much of gravity you want to negate. 0 for nothing and 1 for total anti-gravity.

2 Likes

can you explain to me what mass+= object:GetMass does??

2 Likes

The += is a compound operator that was introduced during Luau’s implementation. Equivalent of:

mass = mass + object:GetMass()

2 Likes

what will i do with this mass?

2 Likes

As I have mentioned earlier, you mathematically calculate one value which, I forgot to mention, should be used for the Y value for the BodyForce.

Also a less relevant point here: Do not use the parent parameter of Instance.new, just parent it after all properties are set.

2 Likes
local function getMassFromModel(model)
	local mass = 0
	for _, object in pairs(model:GetDescendants()) do
		if object:IsA("BasePart") then
			mass += object:GetMass
		end
	end
	
	return mass
end
local bodyforce = Instance.new("BodyForce")
bodyforce.Force = getMassFromModel

I dont know what to do

1 Like