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

Why am I getting a lot of "MatchTags" even though I said only do once?

Asked by
Nep_Ryker 131
6 years ago
Edited 6 years ago

Here Is the code:

players = {} -- Only one player which is me whenever I test the game, so it should do only once right???

for _, player in pairs(game.Players:GetPlayers()) do
    -- Teleport Players
    local spawns = game.Workspace:WaitForChild("Spawns"):GetChildren()
    local spawnsBil = #spawns
    for _, player in pairs(players) do
        if player and player.Character and #spawns > 0 then
            for i = 1, #players do
                local torso = players[i].Character:WaitForChild("UpperTorso")
                local spawnIndex = math.random(1, spawnsBil)
                local Spawn = spawns[spawnIndex]
                if Spawn and torso then
                    table.remove(spawns, spawnIndex)
                    torso.CFrame = CFrame.new(Spawn.Position + Vector3.new(0,3,0))
                -- HERE IS THE CODE THAT GIVES THE PLAYER MATCHTAGS.
                    local matchTag = Instance.new("StringValue")
                    matchTag.Name = "MatchTag"
                    matchTag.Parent = players[i].Character
                -- ENDS HERE.           
                end
            end
        end
    end -- End of this for loop
    print("Teleport?")
end

The script should only give me one MatchTag because I'm the only one in the game but it gives me like 20 MatchTags instead. Any ideas??? thanks.

Answer this question