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)