If so, how? I need to remove the weight from players's hats when they enter the server.
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
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?