Hi, I am trying to make a queue pad(Like in games like "The Purge" etc) I used simple functions like Touched and TouchEnded, but it is so buggy.
My main problem is that when a player is standing on the pad, it keeps removing them from the table and then adding them back. Also, if you step off sometimes, it doesn't remove you.
I just want to know if there are any changes or things I can add to fix those problems.
_G.waitinginline = {}
local countdownon = false
function tablecontains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
function tablefind(tab,el)
for index, value in pairs(tab) do
if value == el then
return index
end
end
end
function showplayer(player)
local clone = game.Lighting.Character:Clone()
clone.Name = player.Name
clone.Namee.Text = player.Name
clone.Frame.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username="..player.Name
clone.Parent = game.Workspace.InLine.SurfaceGui.PlayersInLine
end
function removeplayer(player)
if game.Workspace.InLine.SurfaceGui.PlayersInLine:FindFirstChild(player.Name) then
game.Workspace.InLine.SurfaceGui.PlayersInLine:FindFirstChild(player.Name):Destroy()
end
end
script.Parent.Touched:connect(function(hitt)
local hit = game.Players:GetPlayerFromCharacter(hitt.Parent)
if #_G.waitinginline < 10 then
if hitt.Name == "Torso" then
if tablecontains(_G.waitinginline, hit) then
else
table.insert(_G.waitinginline, hit)
showplayer(hit)
game.ReplicatedStorage.InLine.Value = #_G.waitinginline
end
end
end
end)
script.Parent.TouchEnded:connect(function(hitt)
local hit = game.Players:GetPlayerFromCharacter(hitt.Parent)
if hitt.Name == "Torso" then
if tablecontains(_G.waitinginline, hit) then
table.remove(_G.waitinginline, tablefind(_G.waitinginline, hit))
removeplayer(hit)
game.ReplicatedStorage.InLine.Value = #_G.waitinginline
else
end
end
end)
:D

3 comments
How would I detect when the player is not in that area?
Iterate through the players in the region and check if the player isn't one of them. Edited the script to add a function that checks.
just wondering how would i make this so if a specific amount of players or plrs were detected in that region it runs a function or runs a piece of code? im very new to scripting and im slowly learning this