Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to remove a hats weight? [closed]

Asked by 8 years ago

If so, how? I need to remove the weight from players's hats when they enter the server.

Closed as Not Constructive by EzraNehemiah_TF2 and M39a9am3R

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 8 years ago

Weight can be defined as the force that gravitation exerts upon a body, which can further be defined as the mass of an object times the acceleration of gravity. In Roblox the acceleration of gravity is 196.2 studs/second^2 and thus the force of gravity is 196.2*mass of an object. So, what we need to do is to add a counter-force to essentially "remove the weight".

The first step would be determining what objects to apply this force to. We can do so with the following code inside a script that is then located inside of game.StarterPlayer.StarterCharacterScripts.

for i, v in pairs(script.Parent:GetChildren()) do --Loop through all objects in a players character
    if v:IsA("Hat") then --Check if  the object is a hat
        if v:FindFirstChild("Handle")  then --Find an object named "Handle" inside of the hat (traditionally inside of hats there is a part titled Handle)
            -- Cancel the force of gravity for v.Handle
        end
    end
end

Now that we have access to the parts we want to negate the force of gravity for all we need to do is actually negate gravity. One way to do so is adding a BodyForce object to it that is equal to the force of gravity. We can do so with the following code:

    local bf=Instance.new("BodyForce", v.Handle) --Create a new BodyForce located in v.Handle
    bf.Force=Vector3.new(0,196.2*v.Handle:GetMass(),0) --Set the force so that it cancels out gravity

Finally all is left is to combine the previous two blocks of code and put them into your game. Once combined we get:

for i, v in pairs(script.Parent:GetChildren()) do --Loop through all objects in a players character
    if v:IsA("Hat") then --Check if  the object is a hat
        if v:FindFirstChild("Handle")  then --Find an object named "Handle" inside of the hat (traditionally inside of hats there is a part titled Handle)
            local bf=Instance.new("BodyForce", v.Handle) --Create a new BodyForce located in v.Handle
            bf.Force=Vector3.new(0,196.2*v.Handle:GetMass(),0) --Set the force so that it cancels out gravity
        end
    end
end
0
You did all that work for a question that's gonna be deleted? Don't try to answer these types of little effort questions because he never tried making the script himself. An explanation on how it works is nice. A whole script is too much. EzraNehemiah_TF2 3552 — 8y
Ad