I have a script where it adds the name of player when it touches the part, but right now it keeps on adding multiple times(every bodypart that touches), and when i touch again it adds additional same person. To prevent that, i want to make a function where it checks if the value already exists so it wont spam the username in table.
Ex.
myTable = {}
local part = script.Parent
part.Touched:Connect(function(registeredTeleport)
if registeredTeleport.Parent:FindFirstChild("Humanoid") then
if registeredTeleport.Parent.Name --[already exists--] then
table.remove(myTable,registeredTeleport.Parent.Name(the one inside table))
elseif registeredTeleport.Parent.Name ~= --[already exist--] then
table.insert(myTable,registeredTeleport.Parent.Name)
end
end
end)
wait(10)
table.sort(myTable)
repeat
local temporaryName = myTable[1]:FindFindFirstChild("Head")
if temporaryName == ~~~~"Head" and temporaryName:FindFirstAncestorOfClass("Model") then
temporaryName.Cframe = Cframe.new(X,Y,Z)
end
table.remove(myTable,[1]
until
#myTable == 0
end

1 comment
the dictionary way worked out. Thank you for help :D