Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Table Printing is Repeating?

Asked by 5 years ago
local players = game:GetService("Players")
function emptyfunc()        
end

script.Parent.Touched:Connect(function(hit)
    emptyfunc()
end)


local playersbyteam = {}

while true do
local touch = script.Parent:GetTouchingParts()
    for i,v in pairs(touch) do
        print(i, ":", v)
            wait(0.5)
local player = players:GetPlayerFromCharacter(v.Parent)
if player then
    if playersbyteam[player.Name]==nil then
    print("Player", player.Name)
    table.insert(playersbyteam,player.Name)
    print("PLAYERS TABLE:")print(unpack(playersbyteam)) 
elseif playersbyteam[player.Name]==true then
    return  
end
else
    print("Not a player")

end
    end
end

That is where my code is currently. Everything works fine until we get to printing out our table. I asked the code not to print it out if player's name is already in the table, but it still does it anyways. The problem I am trying to overcome here is the the player's name being printed out every 0.5 seconds to no extent or until they walk off;

1 answer

Log in to vote
0
Answered by 5 years ago

You have the printing in while true do FIRST without checking if it has been printed already, just swap the order.

Ad

Answer this question