Queue System Breaking

I am trying to make a queue system that walks people to a certain point.

  1. If two people enter the queue they stack on each other.

  2. People can break the queue by just moving while it is walking them to the point.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried setting the speed when they reach the destination that worked, but only when they reach the point. They can still move while walking there.
    I also tried setting the player’s walk speed but it won’t walk them to it when the walk speed is 0

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local hum = hit.Parent.Humanoid
		
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if player then
			hum:MoveTo(game.Workspace.WalkToPoint.Position, game.Workspace.WalkToPoint)
			player.PlayerGui.LeaveQueue.TextButton.Visible = true
			wait(8.5)
			hum.WalkSpeed = 0
		end		
	end
end)
1 Like

Disable the controls of the player, this allows them not to be able to move while you can still move them.

local Controller = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
Controller:Disable()

You could use PathService

Ok. Thank you so much!!!

But would it be possible to do this from a server script? :thinking:

But would it be possible to do this from a server script?

Yes, you can fire a RemoteEvent from the server to tell the client to disable controls.

If two people enter the queue they stack on each other.

As for this problem, you’d have to come up with some way of keeping track of the players in the queue.

You can set up different points where players will stand in the queue like this:

image

And then represent the queue as an array, so you can use that in your script, where the index is the position in queue (so 1 is the front or vice versa), and the value is the the player that is currently standing in that position, with 0 being no one.

local queue = {
	[1] = 0,
	[2] = 0,
	[3] = 0,
	[4] = 0,
	[5] = 0,
}

And from there, you can manipulate the queue - I might personally suggest three functions: adding a player to the queue, removing a player from the queue, and updating the queue.

Here’s an example of what I might write for adding a player to the queue. Take a look at my comments ~

local function AddToQueue(player, humanoid)
    --[[
        Creating a variable to store what 'node' to move the player to.
        It's being initialised as 0, as we don't know where the next
        available free space for the player to move to.
    ]]
	local node = 0
	
    --[[
        Looping through the queue, if the value (where the player
        is stored) is 0, then we know that the position has no 
        one there, so we can set our variable `node` to be the 
        node we just found in the loop.
    ]]
	for index,value in ipairs(queue) do
		if value == 0 then -- If empty

			node = index -- Set `node` to the empty one we've just found

			break -- Stop checking, since we've found a free spot
		end
	end
	
    --[[
        Once we've looped through the queue, first check if 
        we found an available spot - if we didn't then `node` will
        still be 0, like we first defined it as. If it isn't 0,
        then we want to set the node to be occupied by the new player,
        and then move the humanoid to that position.
    ]]
	if node ~= 0 then -- If there is a free spot

		queue[node] = player -- Set that spot to the new player
		
		humanoid:MoveTo(nodes[node].Position) -- Move the humanoid (reference to the part's position)
		
	else
		-- Queue is full!
	end
end

This is the result:

There isn’t no right answer, but this is how I would go about it.

-totally not understanding what you just said- :flushed:

Finally figured it out. Lol. One problem tho, it goes in reverse. it starts at 5 then goes to 4 then 3 then 2 then 1. lol.

Apparently that is not the only problem. as soon as one person gets in the queue, it says it is full…

Hey, sorry for the late reply.

I’m not sure why it would loop in reverse - do you mean the array is searched in reverse, or the player moves to the 5th part in the queue?

as soon as one person gets in the queue, it says it is full…

This is because the touched event is fired multiple times when the character touches it, and therefore the same player can be added to the queue over and over again, which is why it might appear full.

The solution would be to add a debounce to the touched event, like so:

Create an empty table to keep track of current players in the queue:

local internalQueue = {
	
}

And in the PlayerAdded function, insert the player into that table:

local function AddToQueue(player, humanoid)
	table.insert(internalQueue, player)
	
     -- code
		
	else
		print("queue is full")
	end
end

And lastly, inside of your touched event, check whether or not the player that touches the part is currently in the queue:

--[[
    Search the table of current players in the queue - if no match is found,
    then add that player to the queue. If there is a match, the condition
    won't pass and the player can't be repeatedly added to the queue i.e. the
    the function can't be spammed.
]]
if not table.find(internalQueue, player) then
	AddToQueue(player, humanoid)	
end

Hopefully this helps out.

Ok!
Thanks so much!
I will try this right now!

Thanks so much!
It worked.
:smiley:

1 Like