Hi’ I’m trying to make a queue sysem, that has stop points, like 10. And when a player touches a part, it :moveTo() the player to the farthest avalible waiting point. When the player’s character arrives, it marks as occupied. If the door is opened, players can exit the queue, but if its not, they just stand there.
I can’t give example, but I want to get this.
If someone has a model or a done script help would be appreciated.
alrighty so first make waiting point parts in your game, name them WaitingPoint1, WaitingPoint2, etc
group these parts under a model or folder named WaitingPoints - if you’re using StreamingEnabled in the game, just so the parts don’t get streamed out, i recommend you use a model and set the model’s streaming mode to Persistent
now put a script in the part that you want the player to touch to enter
replace the script’s default code with this:
local waitingPoints = workspace.WaitingPoints:GetChildren()
local occupiedPoints = {}
--finds the farthest available waiting point
local function getFarthestAvailablePoint()
for i = #waitingPoints, 1, -1 do
if not occupiedPoints[i] then
return waitingPoints[i], i
end
end
return nil
end
local function onTouch(part)
local character = part.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(character)
local waitingPoint, index = getFarthestAvailablePoint()
if waitingPoint then
character:SetPrimaryPartCFrame(waitingPoint.CFrame)
occupiedPoints[index] = player
--(assuming you have a door script)
local door = workspace:FindFirstChild("Door")
if door and door:IsA("Model") then
local doorOpen = door:GetAttribute("Open") --(if there's an attribute to check door state)
if doorOpen then
table.remove(occupiedPoints, index)
-- now u handle exit logic here
end
end
else
player:Kick("No available waiting points in the queue.")
end
end
end
script.Parent.Touched:Connect(onTouch)
now for the door logic (under door part or wtv):
local door = script.Parent
function openDoor()
door:SetAttribute("Open", true)
-- over here code however you wanna open the door, e.g. tweening position, etc
end
function closeDoor()
door:SetAttribute("Open", false)
-- over here code however you wanna close the door, e.g. tweening position, etc
end
-- so u need to use functions openDoor() and closeDoor() to control the door as needed
yeah uhhh itll be smth like this
now u need to edit the main queue script to allow players to exit when the door opens - u can do this by removing the player from the occupiedPoints table and taking them to an exit point
by what i gave, when completed, players should be moved to the farthest available waiting point, and they should stay there until the door opens
anyways cya and lmk if u need anything thing else or have questions etc