Script that sets your mass to 0 when sat

So I need a script that sets the players mass to 0 when they’re sat down in a seat, but set it back to normal once they get up (the spacebar is pressed) Thats basically it. I need it to be inside (a parent of) the seat. How would I script this?

If you could provide a bit of context, that would be nice. Can you please mention the reason as to why you want to change a character’s parts to have 0 mass?

Well, its causing issues like bugs to happen. I don’t need to go into details as its not necessary really.

Alright so, Seats have a Occupant property that is set to the Humanoid who sits down and of course set to nil if there is no Humanoid sitting. Thankfully, you can use :GetPropertyChangedSignal for individually the Occupant.

Now, you’ll need to define three variables - one for the previous Humanoid who sat down (don’t assign it to anything yet) and one for what to set their CustomPhysicalProperties to (Density will of course be 0) yet also the default PhysicalProperties for when they leave the seat

When the signal returned from GetPropertyChangedSignal is fired, check if there is an Occupant.
If so, iterate through it’s Parent’s descendants while setting their CustomPhysicalProperties to the variable you defined - remember to assign to the previous Humanoid variable.

Otherwise, set the CustomPhysicalProperties back to the default variable, and redefine the previous Humanoid variable and dictionary.

Putting that into action:

--// Variables
local Seat = script.Parent.Seat
local PreviousHumanoid
local DefaultProperties = PhysicalProperties.new(0.7, 0.3, 0.5, 1, 1)
local Properties = PhysicalProperties.new(0, .1, .3, 1, 1)

--// Function
local function occupantChanged()
    if Seat.Occupant then
        for _, basePart in ipairs(Seat.Occupant.Parent:GetDescendants()) do
            if basePart:IsA("BasePart") then
                basePart.CustomPhysicalProperties = Properties
            end
        end
        PreviousHumanoid = Seat.Occupant
    elseif PreviousHumanoid then
        for _, basePart in ipairs(PreviousHumanoid.Parent:GetDescendants()) do
            if basePart:IsA("BasePart") then
                basePart.CustomPhysicalProperties = DefaultProperties
            end
        end
        PreviousHumanoid = nil
    end
end

--// Connections
Seat:GetPropertyChangedSignal("Occupant"):Connect(occupantChanged)

EDIT: Made some differences, due to the fact CustomPhysicalProperties isn’t automatically set - now it uses a default variable.

Tested it in studio and works all fine.

2 Likes