How to make a Touch Area

Hello, I’m creating a system using a Touch Area, a Script and a BilBoardGui. When the player touches the area the script clone the BilBoardGui inside the playerGui of the player, but I’ve a problem: the script clones multiple times the BilBoard and this is because I used Touched and ToucheEnded Event, so how can I do to make that when the player touches the Area the Gui shows up and when the player go out the area it disappears (in a server script ) ?

That’s where a debounce comes in.

Here’s an example I threw together just now:

local players = game:GetService('Players')
local part = workspace:WaitForChild('Part')
function CharacterTouchingPart(character,part)
	for _,v in pairs(workspace:GetPartsInPart(part)) do
		if v.Parent == character then
			return true
		end
	end
end
local debounce = {}
part.Touched:Connect(function(hit)
	local name = hit.Parent.Name
	if players:FindFirstChild(name) and not table.find(debounce,name) then
		table.insert(debounce,name)
		-- do stuff here
		while CharacterTouchingPart(hit.Parent,part) do
			task.wait()
		end
		table.remove(debounce,table.find(debounce,name))
	end
end)

I wouldn’t use TouchEnded as touch is very unreliable. Waiting until the player’s character is no longer touching the part is much more accurate.

1 Like

I tried to use ur solution but my Part is not on the workspace and Studio says to me that “GetPartsInPart” is no valid cause my part is parented with a Seat inside a Car so how can I solve it ?