Roblox character not moving with ApplyImpulse method

I have this code and i am wondering why any character in my table would not be flung?

-- Evict the players
			for _, character in ipairs(charactersToEvict) do
				if character.Parent then
					local root = character:FindFirstChild("Head")
					if root then
						local ownerHRP = ownerCharacter:FindFirstChild("HumanoidRootPart")
						if ownerHRP then
							-- Calculate total character mass
							local totalMass = 0
							for _, part in ipairs(character:GetDescendants()) do
								if part:IsA("BasePart") then
									totalMass += part:GetMass()
								end
							end
							
							-- Ragdoll effect
							local humanoid = character:FindFirstChildOfClass("Humanoid")
							if humanoid then
								humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
							end

							local direction = (root.Position - ownerHRP.Position).Unit
							local upwardBoost = Vector3.new(0, 50, 0)
							local impulseVector = (direction * totalMass * 1000) + upwardBoost -- 10 = impulse multiplier

							-- Apply the impulse
							root:ApplyImpulse(impulseVector)
						end
					end
				end
			end

Thank you!

You can’t directly apply velocity on parts owned by players.

Instead look into:

  • RemoteEvents to communicate to target clients to let them handle applying it themselves.
  • Mover constraints which replicate to the client, in turn also letting them handle it.
  • Temporarily setting the NetworkOwner of the character to the server, though this approach is less than ideal due to stuttering and input lag.
1 Like

Thank you, wasn’t aware of that.

Is there a difference in performance between using apply impulse* via client-server communication vs moving constraints?

My game has a lot of moving parts so this would be handy to know.

Also are there any other types of physical things that the player should be controlling?

I know of animations but please let me know.

Thank you!

Using mover constraints grants you a lot more flexibility than using :ApplyImpulse() (unless you want absolute control over it and want to handle all calculations yourself).

Instances will obviously use more resources than a hard-coded API call, but it’s a tiny price to pay for the built-in features and convenience.

The most optimal solution is to let the client handle creation of the mover constraint, if you only need to apply an instantaneous force though, ApplyImpulse will be better.

1 Like

Thanks again : ) lots of handy info

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.