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
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.