Issue with bodyforce

Hey,

im trying to change the players gravity locally by using bodyforce.

However, when the script runs no bodyforce is being added to the bodyparts.

local player = game.Players.LocalPlayer

    local bodyForce = Instance.new("BodyForce")
    for _, bodyPart in ipairs(player.Character:GetDescendants()) do
        if bodyPart:IsA("BasePart") then
            bodyForce.Force = Vector3.new(0, bodyPart:GetMass() * 50 * workspace.Gravity, 0) -- The force required to simulate gravity on the moon
            bodyForce.Parent = bodyPart
        end
    end

Because you are applying the BodyForce only to one part, as you arent crratong multiple in the loop

Also BodyForce is Deprecated.

Well I have no other choice than to use bodyforce.
But isnt it looping through all the bodyparts?

Incorrect. You can use the official successor, which is VectorForce:

2 Likes

Changed my code

local player = game.Players.LocalPlayer

for _, bodyPart in ipairs(player.Character:GetDescendants()) do
    if bodyPart:IsA("BasePart") then
        local vectorForce = Instance.new("VectorForce")
        vectorForce.Force = Vector3.new(0, bodyPart:GetMass() * 50 * workspace.Gravity, 0) 
        vectorForce.ApplyAtCenterOfMass = true
        vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
        vectorForce.Parent = bodyPart
    end
end

but the gravity is still not changed.

1 Like