Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a Region3 or any alternatives?

I want something like: if the player is in a region How to make it?

More in-depth, I have a game about fishing. I want to achieve, when a player is in the region, allow leveling up.

Basically a Region3. It's really hard to describe, sorry. :P

1 answer

✓ Accepted answer

How is a Region3 made?

The Region3.new function needs two parameters: a minimum vector, and a maximum vector. The way how it's constructed is that it will form a box with the minimum at one end and maximum at the other. (I could get a drawing to better explain it, but I can't)

Here's a function that allows you to easily create a region3 with a position and size, also added it where it'll create a part at where the region is:

local function create(position, size)
    local s = size * 0.5
    local p = Instance.new('Part')
    p.BrickColor = BrickColor.new('Lily white')
    p.Transparency = 0.5
    p.CanCollide = false
    p.Anchored = true
    p.Size = size
    p.Position = position - s
    p.Parent = workspace
 
    local min = position - s
    local max = position + s
    return Region3.new(min, max)
end

Here's how you could detect parts and players in a region3:

local r = create(Vector3.new(), Vector3.new(20, 20, 20))
local parts = workspace:FindPartsInRegion3(r, nil, math.huge)

for _,v in pairs(parts) do
    print(v.Name, v:GetFullName())
    
    local p = game.Players:GetPlayerFromCharacter(v.Parent)
    if p then
        print('We found a player: '.. p.Name)
    end
end

Just so you know:

The script above only works once, if you want to constantly check if it's in the region3, you're gonna need a while or repeat loop.

2 comments

0

I worked on Minecraft Servers so I basically know regions (/region XD) better than you, but didn't know how to make them in Roblox xD

0

But, could you please explain (maybe in another answer field) how to make a region from part?

This discussion is preserved as it was. New answers, comments, and votes are closed.