Im trying to make a game where you can get points every second but only if you stay in a spefic area.. I've trie to search it everywhere but havent found anything..
How do i make so that players get points every second? But only when they are in a specific area?
1 answer
Hi I may have an answer for your question. You should use FindPartsInRegion3. In order to do this, you must imagine a square for your area. You must pick the top left corner of your square and find its position and you must pick the bottom right of your square and find its position.
this is the top left corner of your square- . --------------------------------------------|
| |
| |
| |
| |
| |
| |
| |
-----------------------------------------------
this is the bottom right corner of your square- .
As illustrated above roblox can make out a square with just 2 points!
lets say out top left corner was 0,0,0 lets say our top right corner was 5,5,5
heres a code:
local Top_left = Vector3.new(0,0,0)
local Top_right = Vector3.new(5,5,5)
local Region = Region3.new(Top_left,Top_right)
for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region)) do
if Part:FindFirstChild == ('Humanoid') then
print('Someone is here!')
else
print('No one is in my area yay social distancing!')
end
You dont need to create a part yourself as far as I know region3.new creates a part automatically!
Hope this was helpful!
Any Questions? just ask!
EDIT: Sorry for the messy square diagram you can make a square out of 2 points on a piece of paper if you want!
2 comments
Have you actually tested it?
doing (if Part:FindFirstChild == ('Humanoid') then) will error and also Part will be a BasePart of the Character so you should do it like this (if Part.Parent:FindFirstChild('Humanoid') then) . When it returns an instance that means it's true otherwise, false
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Using a region 3 will help. Here's a tutorial https://www.youtube.com/watch?v=XAwoodFJWos and the developer wiki https://developer.roblox.com/en-us/api-reference/datatype/Region3