--- Load and create constants

local AntiGravityForce      = Instance.new("BodyForce")
AntiGravityForce.Name       = "GravityCoilEffect"
AntiGravityForce.Archivable = false

local Handle           = WaitForChild(Tool, "Handle")
local CoilSound        = WaitForChild(Handle, "CoilSound")
local GravityMaid      = MakeMaid() -- Will contain and maintain events

local function UpdateGravityEffect(Character)
	-- Updates the AntiGravityForce to match the force of gravity on the character

	local Bricks
	if Character:IsDescendantOf(game) and Character:FindFirstChild("HumanoidRootPart") and Character.HumanoidRootPart:IsA("BasePart") then
		local BasePart = Character.HumanoidRootPart
		Bricks         = BasePart:GetConnectedParts(true) -- Recursive
	else
		warn("[UpdateGravityEffect] - Character failed to have a HumanoidRootPart or something")
		Bricks = GetBricks(Character)
	end

	local TotalMass = 0

	-- Calculate total mass of player
	for _, Part in pairs(Bricks) do
		TotalMass = TotalMass + Part:GetMass()
	end

	-- Force = Mass * Acceleration
	local ForceOnCharacter         = GravityAccelerationConstant * TotalMass
	local CounteringForceMagnitude = (1 - 0.25) * ForceOnCharacter

	-- Set the actual value...
	AntiGravityForce.force = Vector3.new(0, CounteringForceMagnitude, 0)
end

