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

Find when a player leaves a Region3?

I'm trying to make a shop gui that'll appear and disappear depending on if the player is in the correct area. The Gui appears when you enter the region, but won't go away. Script:

local RegionPart = workspace.GemTradeVisual
local Region = Region3.new(RegionPart.Position - (RegionPart.Size/2),RegionPart.Position + (RegionPart.Size/2))
local Detected = false
local Player = game:GetService("Players").LocalPlayer local Char = Player.Character or Player.CharacterAdded:Wait()
wait()
RegionPart:Destroy()

while wait(1) do
	local Detect = workspace:FindPartsInRegion3WithWhiteList(Region,game.Players.LocalPlayer.Character:GetDescendants(),math.huge)
	for _,v in pairs(Detect) do
		if v.Parent.Name == Player.Name then
			Detected = true
			break
		else
			Detected = false
			print(v)
		end
	end
	if Detected then
		Player.PlayerGui.SellGems.Enabled = true
	else
		Player.PlayerGui.SellGems.Enabled = false
	end
end

1 answer

✓ Accepted answer

You already whitelisted the LocalPlayer, you don't need to check if they are in the circle. Any parts collected will be a part of that player.

local RegionPart = workspace:WaitForChild("GemTradeVisual")
local Region = Region3.new(RegionPart.Position - (RegionPart.Size/2),RegionPart.Position + (RegionPart.Size/2))
local Player = game:GetService("Players").LocalPlayer local Char = Player.Character or Player.CharacterAdded:Wait()
local SellGems = Player.PlayerGui:WaitForChild("SellGems")
wait()
RegionPart:Destroy()

while wait(1) do
    local Detect = workspace:FindPartsInRegion3WithWhiteList(Region,Char:GetDescendants(),math.huge)
 	SellGems.Enabled = #Detect > 0
end

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