Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is the best way to change a player's gravity? [Un-answered]

local Tool = script.Parent
local Character
local Gravity = 0.75
local bodyForce

GetClass = function(instance, class, recursive)
	local children = {}
	for _, child in pairs(instance:GetChildren()) do
		if child.ClassName == class then
 			table.insert(children, child)
		end
		if recursive then
			local result = GetClass(child, class, true)
			if result then
				for _, v in pairs(result) do
					table.insert(children, v)
				end
			end
		end
	end
	return children
end

local createForce = function()
	local TotalMass = 0
	for _, part in pairs(GetClass(Character, "Part", true)) do
		if part.Name ~= "Handle" then
			TotalMass = TotalMass + part:GetMass() * 196.2 * Gravity
		else
			TotalMass = TotalMass + part:GetMass() * 196.2 * 1
		end
	end
	
	if bodyForce then bodyForce:Destroy() end
	bodyForce = Instance.new("BodyForce", Character.Torso)
	bodyForce.Name = "GravityEffect"
	bodyForce.force = Vector3.new(0, TotalMass, 0)
end

local onEquipped = function()
	local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
	Character = Player.Character
	Tool.Handle.CoilSound:Play()
	
	createForce()
	
	Character.ChildRemoved:connect(function(child)
		if child:IsA("Hat") then
			createForce()
		end
	end)
	Character.ChildAdded:connect(function()
		createForce()
	end)
end

local onUnequipped = function()
	if bodyForce then bodyForce:Destroy() end
end

Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)

This is a script I made for a gravity coil but it doesn't work like I want it to. I want to make a gravity coil that makes all player's go the same height when they use it, but hat's always seem to... well, not make that happen. What is the best way to make it so that no matter what, people will go the same height with the gravity coil and hats won't effect it?

1 answer

I would recommend using a bodyvelocity, also can be a bit glitchy :/

This discussion is preserved as it was. New answers, comments, and votes are closed.