Detecting when a player leaves region3?

currently working on a molotov and i have a region3 set up that detects when a player enters the region every heartbeat, this works fine, but now i need to detect when a player leaves it. not sure how to go about this. i do not want to use touchended for this.

Mind sharing the script you’re working with? Should be a fairly simple change.

Here is a reply I made on another post with the same question, I hope it helps! https://devforum.roblox.com/t/how-do-i-check-if-a-player-leaves-the-region3/1661691/7

local Run = game:GetService("RunService")
local Players = game:GetService("Players")

local Part = script.Parent
local Region = Region3.new(Vector3.new(Part.Position.X - Part.Size.X/2, Part.Position.Y - Part.Size.Y/2, Part.Position.Z - Part.Size.Z/2), Vector3.new(Part.Position.X + Part.Size.X/2, Part.Position.Y + Part.Size.Y/2, Part.Position.Z + Part.Size.Z/2))

local PlayersInRegion = {}

Run.Stepped:Connect(function()
	PlayersInRegion = {}
	local PartsInRegion = workspace:FindPartsInRegion3(Region)
	for _, Part in ipairs(PartsInRegion) do
		local Model = Part:FindFirstAncestorOfClass("Model")
		if Model then
			local Player = Players:GetPlayerFromCharacter(Model)
			if Player then
				PlayersInRegion[Player] = true
			end
		end
	end
end)

Here’s a script I just wrote which should help visualize what you need to do/change.

The “PlayersInRegion” dictionary is emptied before each Region3 query occurs, if players are found within the designated region then they are inserted into this dictionary.

2 Likes

changed some things to suit my code and it works perfectly, thanks