How to check if a player is above or touching a certain model?

I’m currently creating a minigame in my game.
Essentially, there are multiple circles and all the players are invisible. Every player will choose a random circle, and at the end of the timer all the players on whichever circle had the most players will die.

How can I detect if and which circle a player is on?
I would use Player.Touching, but that would mean if they were jumping it wouldn’t detect them when counting the players.

Edit: In stickmasterluke’s fencing game, he only lets you kill players on the PVP square. This is kind of what I want, but not with swords.

At the end of the time, use Region3 to detect how many players are in each circle. Kill the players in whichever has the most.

2 Likes

Since it’s a circle, you could check if the magnitude from the center of the circle to each player is less than or equal to the radius of the circle in 2D. You could do something like this:

local playerPosition = character.HumanoidRootPart.CFrame.p
local circlePosition = circle.CFrame.p
local playerXZ = Vector2.new(playerPosition.X, playerPosition.Z)
local circleXZ = Vector2.new(circlePosition.X, circlePosition.Z)

if (playerXZ - circleXZ).Magnitude < circleRadius then
    -- Player on circle
else
    -- Player not on circle
end

I did this from my head so there may be a few issues with this code, but it should give you an idea of what I mean. You could use Vector3s as well with the Y said to 0, but I used Vector2s for this example. With this method you don’t have to worry about collisions, events or jumping. Although it has some drawbacks like not being able to detect if a player is actually touching it.

Though this is well thought out, this may give false positive depending on where you are recording the player’s position from. It would be more appropriate to attempt @Kymaraaa 's Region3 checks idea instead.

For example, recording the root Part’s position vs the feet’s position could give different magnitudes.

Yeah, like I said it has some drawbacks, it’s more case-specific but it would be pretty reliable if implemented well. You could for example when necessary loop through all players and use that piece of code to determine if they’re on the circle at the end of each round.

Also there’s no issue with root/feet position since it only checks the X and Z axes, never Y thus eliminating the distance issue caused by choosing the wrong point.

I meant to say like the feet could be extended out beyond the root Part’s position, small changes like that.

How would I use Region3 with a circle?

Ohh, yeah that’s true, but if you just use rootposition at all times there wouldn’t be an issue with it unless people stand tip-toe on the edge, and if you want to be extra sure you could just repeat the code for each foot and check if either of them are within the boundaries.

Either way, Region3 works too but the difference is that it’s a box instead of a cylinder, so you could get false-positives if people are in the corners which ingame would look like they’re falling off.

Use the diameter of the circle as the distance needed to be covered in Region3 s.

I’ve got it working. Thanks for your help, everyone.

Make sure to mark a post as the solution so others can find solutions if they had similar questions in mind.