How to make it so entering and exiting a non collidable part triggers an event

So as the title suggests, I just wanted to know what should i use if i wanted to make it so if a player enters a that is uncollidable, an event is triggered, and until they leave the part, another event triggers.

An example of this would be like when a player enters a room a sound plays and when he leaves the room, the sound stops playing.

Or when someone enters a location like a cave, the lighting changes making it dark, and when they leave the lighting returns to normal.

All i need to know is what i need to use in order to make this come to life.

thanks.

1 Like

ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries - Resources / Community Resources - Developer Forum | Roblox

i found this one day, it does logic when you enter a zone (aka invisible part without collision)

There is a full tutorial explaining - sorry but i don’t have time to fully explain right now

1 Like

All Parts have a .Touched and .TouchEnded event which you can connect to

local Players = game:GetService('Players')
local Part = workspace.Part

Part.Touched:Connect(function(touch) 
    for _, player in pairs(Players:GetPlayers()) do
        if touch:IsDescendantOf(player.Character) then
            print(`{player} entered zone`)
        end
    end
end)

Part.TouchedEnded:Connect(function(touch) 
   for _, player in pairs(Players:GetPlayers()) do
        if touch:IsDescendantOf(player.Character) then
            print(`{player} left zone`)
        end
    end
end)

While that would work, I wouldn’t recommend using Touch events as they are unpredictable at times, usually Region3s work better.

1 Like

FindPartsInRegion3 is depricated now sadly.

I made a post about how to do this, feel free to read it: How would I check if a Player is in a part (Part.Touched, Region3 or other) - #8 by pf_z1

1 Like

I actually did the same thing as u can see here:

script.Parent.Touched:Connect(function(toucher)
	if toucher.Parent:FindFirstChild("Humanoid") then
		game.Workspace.Sounds["Underwater Ambience"]:Play()
	end
end)

script.Parent.TouchEnded:Connect(function(toucher)
	if toucher.Parent:FindFirstChild("Humanoid") then
		game.Workspace.Sounds["Underwater Ambience"]:stop()
	end
end)

But the problem is that its kinda glitchy, since as you mention, its unpredictable at times. But for the most part it does work. I might actually try Region3s instead.

Region3s are usually to go to, although as @pf_z1 mentioned, they are deprecated for the new methods of workspace :GetPartInBoundBox(), :GetPartBoundsInRadius() and :GetPartsInPart()

The third method is generally the most accurate but is likely in excess for what you need for precision. Although, it does accept a Part to denote a region which may be useful in your case.

Another thing to note is that .Touched events for client-owned parts interacting with other client-owned parts (like the player character) are more accurately reported when the event is also bound on the client. (With the exception of fast moving stuff which is just generally not registered well with .Touched)