More efficient method than .Touched

So .Touched is really buggy for me and i can’t get this queue system to work, im trying to make it when they enter they are put into a queue but when they leave they are removed from the queue but for some reason it doesn’t wanna work, im not sure if this is .Touched or just generally my script.

queuePart.Touched:Connect(function(hit)
	if not db then
	db = true
	stillTouching=true
	for _,queued in pairs(queuePart.Queue:GetChildren()) do --Get all the queued intvalues
	if hit.Parent.Name == "Body" or hit.Parent.Name == "Colour" then --Check if it's a car (works)
	if hit.Parent.Parent.Parent.DriveSeat.Owner.Value then
		player = hit.Parent.Parent.Parent.DriveSeat.Owner.Value --Gets the player from the seat
	end
	if queued.Value ~= player then --Checks if the queued value isn't the same as the player name already so it doesn't add it again
	table.insert(playersQueued,player) --Adds the player to the queued table
	queue=queue+1 --Adds 1 to the queue (to know how many people are racing)
	queued.Value = player --Set the string value to their name
	local queueGui = getGui(player) -- I have a function which gets the gui by their name
	car = hit.Parent.Parent.Parent --Get the car
	if not disabled then
	queueGui.queue.Text = text.." - "..queue.."/"..queueSize --Set the queue text (works)
	else
	queueGui.queue.Text = "Racing disabled due to issues."
	end
	break
	end
	end
	end
	wait(2)
	db = false
	end
end)

queuePart.TouchEnded:Connect(function(hit)
	if not db and not disabled then
	db = true
	stillTouching=false
	print("Stopped touching") --This doesn't print
	for _,queued in pairs(queuePart.Queue:GetChildren()) do
	if hit.Parent.Name == "Body" or hit.Parent.Name == "Colour" then
	playersQueued[player] = nil --Find the player in the queued table and remove them
	player = hit.Parent.Parent.Parent.DriveSeat.Owner.Value
	if queued.Value == player then
	queue=queue-1
	queued.Value = "none"
	local queueGui = getGui(player)
	car = hit.Parent.Parent.Parent
	queueGui.queue.Text = ""
	break
	end
	elseif hit.Parent.Name == "Wheel" then
	for _,queued in pairs(queuePart.Queue:GetChildren()) do
	if hit.Parent.Name == "Body" or hit.Parent.Name == "Colour" then
	playersQueued[player] = nil
	player = hit.Parent.Parent.Parent.DriveSeat.Owner.Value
	if queued.Value == player then
	queue=queue-1
	queued.Value = "none"
	local queueGui = getGui(player)
	car = hit.Parent.Parent.Parent
	queueGui.queue.Text = ""
	break
	end
	end
	end
	end
	end
	wait(2)
	db = false
	else
	local queueGui = getGui(player)
	queueGui.queue.Text = ""
	end
end)

No idea what your architecture is like, but I’m assuming this is a part on the floor and if they’re touching it, they’re in the queue?

If so, you’d likely be better off using Region3 and checking to see if they’re inside the region - if they are, they’re added to the queue and their position tracked until they leave the queue.

If it’s a circle object on the floor, that’s even easier: just check to see if their magnitude is within the bounds of the diameter of the circle.

I’m trying to use EgoMoose’s Rotated Region 3 Module to check the region. If that doesn’t work i’ll consider the magnitude method.

Ok it didn’t seem to work, this is what i tried

local function getRegion3Parts() return region3Module:fromPart(queuePart) end

while wait() do

local hit = getRegion3Parts()

print(hit.Name)

end

I created Zone+ to solve this exact issue! Simply do:

local ZonePlus = require(4664437268)
local ZoneService = require(ZonePlus.ZoneService)
local group = workspace.AFolderContainingYourZonesParts
local zone = ZoneService:createZone("ZoneName", group, 15)

zone.playerAdded:Connect(function(player)
	print(player.Name,"entered the zone!")
end)
zone.playerRemoving:Connect(function(player)
	print(player.Name,"exited the zone!")
end)
zone:initLoop()
2 Likes

Looks easy to use, i’ll try that right now.