How do I prevent a character from going below a certain height?

I want to create a minimum height that characters (but nothing else) effectively cannot go below. When a character hits that height, they should be unable to go any lower, as if there’s an invisible floor there. I have been trying to use body movers to do this for multiple hours, and it’s become clear that I really have no idea what I’m doing. How would you do this?

why could you not simply make an invisible part that is at your height with collision? this would seemingly achieve what you are after. You can also loop check a player’s Y value to make sure its >= the height you are looking for

I did this before, create a part that follow the players Y axis and make it so that it is locked onto the players axis

1 Like

I have already considered using an invisible part combined with physics layers. However, doing so could cause all sorts of issues. For example, footstep sounds would play when the character moved even though they’re supposed to be hovering, the player would have the ability to jump despite the fact that they’re not supposed to be touching the ground, et cetera. If I picked that solution I would have to fix all of these problems one by one. If there’s a single solution I can use that does not force me to come up with a bunch of hacky fixes, I’d rather pick that one.

As for your second proposed solution, what should I do when the player’s Y value is below the desired height? Should I teleport the player back up?

Solution: Just use a basic part and make the material ForceField, this way, footstep sounds wouldn’t be a problem. Idk about the jumping part though

I could easily fix the jumping. That solution seems like it could technically work. However, It’s kind of a hacky and flawed solution. I’m not going to completely rule that solution out, but I’d still like to see if there’s a better one. Thanks for the help!

(I’m not trying to be disrespectful, I just don’t want to type all this out again.)

I’m not sure if this would work, but you could just have a while loop that checks the how low the character is. I made it so the higher the character is, the more it will wait before checking again, to reduce lag.

local maxDepth = -1000

game.Players.PlayerAdded:Connect(function(player)
       player.CharacterAdded:Connect(function(char)
           local waitTime = 1
           while true do
                  if char.Parent ~= workspace then break end
                  if char.HumanoidRootPart.Position.Y < maxDepth then
                     local velocity = Instance.new("BodyVelocity", char.HumanoidRootPart)
                     velocity.Velocity = Vector3.new(0,0,0)
                     break
                  end 
                  local distance = math.abs(maxDepth + char.HumanoidRootPart.Position.Y)
                  waitTime = math.clamp(math.sqrt(distance/1000),0.2,2)
                  wait(waitTime)
           end 
       end
end)

Huh… it didn’t occur to me that you could use bodyVelocity like that. I’m going to experiment with it to see if I can get my desired result.