How to make a block that gives you gravity

image

Could you possibly explain a little bit more on what your trying to achieve? Do you want the part to make a player float or?

1 Like

Check If this helps

– zone anti gravity
– okeanskiy

---- Localize
– player related instances
local player = game.Players.LocalPlayer
local character = player.Character
local bodyForce = Instance.new(“BodyForce”)

---- Information
– zones to touch
local zones = {
ZoneA = workspace.Tunnel.Zones.ZoneA,
ZoneB = workspace.Tunnel.Zones.ZoneB
}

– debounces for each zone
local debounces = {
ZoneA = false,
ZoneB = false
}

– how much anti gravity strength for each zone
local antiGravityMultipliers = {
ZoneA = 1.05,
ZoneB = 0
}

---- Functions
– make the descendant baseparts of any instance massless
– with the exception of “HumanoidRootPart”
function makeMassless(parent)
for descendantIndex, descendant in pairs(parent:GetDescendants()) do
if descendant:IsA(“BasePart”) and descendant.Name ~= “HumanoidRootPart” then
descendant.Massless = true
end
end

-- massless to any children added to that parent later
-- such as parts, tools, and hats
parent.ChildAdded:Connect(function(child)
	if child:IsA("BasePart") then
		child.Massless = true
	end
end)

end

– set an antigravity force onto our bodyforce
function setAntiGravity(zoneName)
local antiGravityMultiplier = antiGravityMultipliers[zoneName]

bodyForce.Force = Vector3.new(0, bodyForce.Parent:GetMass() * workspace.Gravity * antiGravityMultiplier, 0)

if antiGravityMultiplier > 1 then
	
	-- change humanoid state to physics for a moment
	-- this will cause the character to 'trip'
	-- and allow them to lift off the groud with new antigravity
	spawn(function()
		character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		
		wait(1)
		
		character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	end)
end

end

– remove all other debounces and set new debounce
function updateDebounce(zoneName)
– remove from debounces of all zones
for zoneName, debounce in pairs(debounces) do
debounces[zoneName] = false
end

-- add to debounces
debounces[zoneName] = true

end

---- Events
– adding touch events to each zone
for zoneName, zonePart in pairs(zones) do

zonePart.Touched:Connect(function(touchedPart)
	local touchPlayer = game.Players:GetPlayerFromCharacter(touchedPart.Parent)
	
	-- check for player and that player is local player and not in debounces
	if touchPlayer and touchPlayer == player and not debounces[zoneName] then
		
		updateDebounce(zoneName)
		
		setAntiGravity(zoneName)
		
	end
end)

end

---- Initialize
– massless the character
makeMassless(character)

– add a body force to the character humanoidrootpart
bodyForce.Name = “ZoneForce”
bodyForce.Force = Vector3.new(0, 0, 0)
bodyForce.Parent = character.HumanoidRootPart

1 Like

Yes, that’s exactly what I want to try to do.