How to have a reliable and easy detector of player when touching a brick?

Hi! I’m trying to make a system where if a player enters a building, they would have certain effects happen onto them, and will be removed once they leave the building. However, I’m having an issue where it keeps registering repeatedly as player entered and player left the building while being in building.

I’ve tried using Touched/TouchEnded and ZonePlus modulescript, but they keep registering as such.
I’m quite new to scripting and reading other answers has stated that it’s best achieved using raycasting etc which I’m not very experienced in. Is there a more friendly method?

1 Like

It’s best to use debounce

Alright well I misunderstood the question. Use some sort of variable that will be either set to true or false depending if the player leaves/enters the zone. If its true, don’t add the effects, else remove them. Something like that. Still kinda confused what you have and what you want

Sorry, let me explain:

Let’s say when a player enters the building, the player’s camera is zoomed in a bit and
CameraMaxZoomDistance is smaller. When the player leaves the building, the camera is zoomed out and the camera is back to normal.

Right now, I’ve tried doing a Bool and set true when touching the floor of the building, the set false once touchended when no longer on the floor. However, it keeps going back and forth true and false as I’m still touching the floor.

I was gonna say Region3, but I feel as though that would be more complicated than what it should be

Just loop through all the players using frequent Magnitude checks with creating a “InvisiblePart” at the center of your Building, then if they’re close use a RemoteEvent to handle server-client transportation using the FireClient() function to change their Local Camera

Old Post from what I was gonna say

I believe Region3 is what you could be looking for? What it does, is that it’ll create a Region (Or 3-dimensional space) and you can check if the Players are in that specific Region or not :thinking:

Simply creating a Region, is that it requires 2 arguments: A minimal value & a maximal value so what we’ll probably need to do is reference a “InvisiblePart” inside the Building

local MinRange = workspace.Part.Position - (workspace.Part.Size * 0.5)
local MaxRange = workspace.Part.Position + (workspace.Part.Size * 0.5)

local Region = Region3.new(MinRange, MaxRange)

Then what we can use is FindPartsInRegion3 encased in a loop, which will frequently check if the Region we just made is near any Players at all:

while true do
    local PartsToFind = workspace:FindPartsInRegion3(Region, Building)
    print(PartsToFind)

    for _, Object in pairs(PartsToFind) do
        local Player = game.Players:GetPlayerFromCharacter(Object.Parent)

        if Player then
            --Do your stuff here
        end
    end
    wait()
end

1 Like

Thanks! This sounds like a good alternative. However, I’d like to ask how would I implement such a system if the house isn’t a square/rectangle. Assuming if the house is a L shaped or a circle shaped.

From my basic knowledge… magnitude would only cover an area that is either a square or a rectangle, yes?

To do that, you can use Region3. Now, don’t understand me wrong but there’s no other TouchedEvents except Region3 and Instance.Touched().

Another thing what you could do is use magnitude. You can check the if the player is near enough the zone. Though this does not check if the player is in the zone, but it will check if it is in the radius of the zone.

Hope it helped.

I believe so, maybe you could use GetTouchingParts() as well & detecting if the Player is currently inside the house or not if you want to detect different shapes since it’ll return back an array of Touching Objects & checking if the Part Touching is equal to a Player’s Character to change the Camera View