#Help with region3

54 messages · Page 1 of 1 (latest)

bleak igloo
#

Never used region 3 before, trying to make an area indicator system.
Saw someone on youtube make one so i tried something similar, but with a module.
code:

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RS = game:GetService("RunService")
local areaIndex = require(script.areaIndex)

local char = player.Character

local folder = game.ReplicatedStorage.GetAreas:InvokeServer()
print(folder)

for _, area in folder do
    print("exist")
    local region = Region3.new(area.Position - (area.Size / 2), area.Position + (area.Size / 2))
    local inRegion = false
    
    local function RenderStepped()
        inRegion = false
        
        local params = OverlapParams.new()
        params.FilterType = Enum.RaycastFilterType.Include
        params.FilterDescendantsInstances = {char}
        
        local parts = workspace:GetPartBoundsInBox(region.CFrame, region.Size, params)
        
        for _,v in parts do
            if v:IsDescendantOf(char) then
                inRegion = true
                break
            else
                continue
            end
        end
        if inRegion then
            print("in da zone")
            areaIndex:SetArea(player,area.Name)
        else
            areaIndex:EndArea(player)
        end
        
    end
    RS.RenderStepped:Connect(RenderStepped)
end

inRegion never returns true for some reason. Ive checked the physical indicator blocks, nothing happens. This is running in a local script in startergui, the module is a child of the local script.
Anyone know why this wont work?

oak sky
#

you are literally filtering out the charcter

#

in your params

#

nvm

#

instead of doing :GetPartBoundsInBox

#

you get the corners of the box

#

and do math to check if the player is inside the box (by comparing x, y, z)

bleak igloo
#

if you know

#

cause it should work

oak sky
#

i aint sure

bleak igloo
#

ive seen someone else do it

#

i compared my code again and it seems fine

bleak igloo
#

how would i go about doing that

#

💀

oak sky
#

alot of math 😢 its possible

bleak igloo
#

not exactly sure where id be able to get the corners specifically from

oak sky
#

but it burns my brain

bleak igloo
#

YIKES

#

ill revisit the original code i sampled from

#

and check api

oak sky
#

if you wanna get the top of the part heres how you might do it

local part = part
local player = game.players.LocalPlayer
local topRightcorner = part.Position + Vector3.new(0, part.Size.Y/2, 0) + Vector3.new(part.Size.X/2, 0, 0)
if player.Character:GetPivot.Position.Y < topRightcorner.Y then

end
#

its just hard to imagine

bleak igloo
#

cause this guy

oak sky
#

kk

#

wait a min

#

your just putting the players char in the params

#

not the children

bleak igloo
#

👁️

oak sky
#

try :GetChildren() on char

bleak igloo
#

i will

#

one sec

oak sky
#

and remove the brackets

#

since GetChildren() returns a table

bleak igloo
#

still broken 😬

#

i did do this differently than the original way it was written tho idk why the changes i made would affect it

oak sky
#

🤔

bleak igloo
#

originally this way was written for putting the script into the "area detector" part

#

instead i iterated through a table of a folder's children (the area parts)

#

and ran code for each one

#

in one script

#

thats the only major difference

bleak igloo
#

couldnt find a fix

icy rapids
bleak igloo
icy rapids
#

Yes

#

You can use my module as a reference

bleak igloo
#

thank you

#

although do you have any idea why the original code isnt working?

#

im trying to figure out what i did wrong

bleak igloo