Low gravity area for spaceship hangout

I would like to make a low gravity area on a spaceship place.
I have tried using a block that you can touch with the gravity api script:

Workspace | Documentation - Roblox Creator Hub

  1. – Calculate the moon’s gravity
  2. local moonGravityRatio = 1.62 / 9.81
  3. local defaultGravity = 196.2
  4. local moonGravity = defaultGravity * moonGravityRatio
  • – Create a touch pad
  1. local pad = Instance.new(“Part”)
  2. pad.Size = Vector3.new(5, 1, 5)
  3. pad.Position = Vector3.new(0, 0.5, 0)
  4. pad.Anchored = true
  5. pad.BrickColor = BrickColor.new(“Bright green”)
  6. pad.Parent = workspace
  • – Listen for pad touch
  1. local enabled = false
  2. local debounce = false
  3. pad.Touched:Connect(function(hit)
  4. if not debounce then
  5. debounce = true
  6. – Toggle gravity between moon and default
  7. enabled = not enabled
  8. workspace.Gravity = enabled and moonGravity or defaultGravity
  9. – Change pad color
  10. pad.BrickColor = enabled and BrickColor.new(“Bright red”) or BrickColor.new(“Bright green”)
  11. wait(1)
  12. debounce = false
  13. end
  14. end)

(the code from the page)
But I would like to make a “zone” that changes the gravity, but only in that said zone (similar to this game Ragdoll Sandbox Dev - Roblox )

You can use coordinates

So like a certian area is gravity changed, would that be like a script?
(I assume sorry lol I’m new to scripting)

You can define the zone by using coordinates. Let’s say the zone is in the shape of a cube. You would define the coordinates of each corner and check if the player is within those coordinates

Or, you can use distance. if the player is a certain amount of distance away from a part, the gravity will change.

if (part.Position - HumanoidRootPart.Position).Magnitude < 5 then

Thanks, the game is working now.

1 Like