How could i push the player 5 studs? - combat system

What am i doing wrong using bodyforce?

local bodyForce = Instance.new("BodyForce")
bodyForce.Force = Vector3.new(0, 1915.52, 0)

That is a lot of force, are you sure you need that much?
You could also use a BodyVelocity maybe?

i just want to push 5 studs to the player, how could i do that? :frowning: could you help me with that please :scream:

Assuming no other agents are in the system -

local bodyForce = Instance.new("BodyForce")
bodyForce.Force = Vector3.new(0, agent:GetMass() * workspace.Gravity * 5, 0)

Is that agent the humanoid right? :open_mouth:

agent = the players mesh, sorry its a term commonly used in AI

it didn’t worked… what is wrong? :frowning:

event2.OnServerEvent:Connect(function(plr, victim)
	-- stam decrease
	local AttackDist = 10 --If a player is further than this value, they won't be damaged.

	for i,v in pairs(game.Players:GetChildren()) do --Loops through all players.		
		if v.Character ~= nil and plr.Character ~= nil and v ~= plr then --Checks if there's a character
			local pRoot = plr.Character:FindFirstChild("HumanoidRootPart")
			local vRoot = v.Character:FindFirstChild("HumanoidRootPart")

			if pRoot and vRoot and (plr.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).Magnitude < AttackDist then --Checks if the Root parts exist and if the player is in range.
				local Hum = v.Character:FindFirstChild("Humanoid")

				if Hum and Hum.Health > 0 then --Checks if player is alive.
					Hum.Health -= 20 --Change "100" to the damage the player should take.
					local text = { -- array containing random text
						"You hit hard!",
						"Keep it up!",
						"You can do this!",
						"Just a bit more!!"
					}
					local textLabel = script.Parent.HitsVar
					textLabel.Text = text[math.random(1, #text)]
					wait(3)
					textLabel.Text = ""	
					
					
					local bodyForce = Instance.new("BodyForce")
					bodyForce.Force = Vector3.new(0, agent:GetMass() * workspace.Gravity * 5, 0)
				end

				--Stuff that happens when a player is in range.
			end
		end
	end
	-- end
end)
  1. you arent parenting the body force to be replicated to workspace
  2. from the current code it seems there is no reference to “agent”
  3. Make sure to add up each agents limbs mass together instead of getting the mass of the model

am i good? :scream: or how could i do that? :frowning:

local agent = plr.Character.HumanoidRootPart
					local bodyForce = Instance.new("BodyForce")
					bodyForce.Force = Vector3.new(0, agent:GetMass() * workspace.Gravity * 5, 0)
					bodyForce.Parent = plr.Character.HumanoidRootPart
local function getMassOfAgent(agent)
  local mass = 0
  for _, v in pairs(1, agent:GetDescendants()) do
    mass += v
  end
end
1 Like