@WarioSvug (WarioSvug) posted a new topic, subject "Object Clone Amount Based On Amount Of Players In The Game". It read:

   You can write your topic however you want, but you need to answer these questions:
    
      1. **What do you want to achieve?** Keep it simple and clear!
    
    
    
    Hey guys, so, I am basically making a hockey league stat system, where I have a GUI that is able to detect who is on what team. If a player is teamed something specific, their name will be added to a UIGrid with stuff inside of them. I've got the part. After that, if I press their name, I will be able to add their name to a separate list, where everybody in the game can see who has a goal/assist/save. But, when I try to add their name to that list, it clones multiple times, in fact, based on the amount of players are in that server.
    
      2. **What is the issue?** Include screenshots / videos if possible!
    
    
    
    https://gyazo.com/b6e8b76df7bdf2c0bedf4f333ec79eb8
    
      3. **What solutions have you tried so far?** Did you look for solutions on the Developer Hub?
    
    
    
    I tried to look through DevForum, and couldn't find anybody with a similar problem. I tried initially using the Server to disperse everybody's UI via the Server, but I came to realize that was a problem. So, instead of using the server, I instead only use the server to tell all of my local people to clone this specific tab from the Replicated Storage, and slap it in the UI.
    
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it's easier for people to help you!
    
    Located within a button. All hierarchy is correct. No errors.
    [code] 
        local button = script.Parent
        local playerName = script.Parent.Parent
        local playerList = playerName.Parent.Parent.Parent.StatSheet.Frame.Players.PlayerDisplay
        local addPlayer2 = game.ReplicatedStorage.AddPlayer2
        local updateGUI2 = game.ReplicatedStorage.UpdateGUI2
        local player = game.Players.LocalPlayer
        local playerToClone2 = game.ReplicatedStorage.Player2
        
        button.MouseButton1Click:Connect(function(player)
        	local playerExists = findPlayer(playerName.Name)
        	if playerExists == false then
        		updateGUI2:FireServer(playerName.Name)
        	end
        end)
        
        updateGUI2.OnClientEvent:Connect(function(playerName)
        	local GUI = player.PlayerGui.StatSheet.Frame.Players.PlayerDisplay
        	local playerClone = playerToClone2:Clone()
        	playerClone.Parent = GUI
        	playerClone.Name = playerName
        	playerClone.Text = playerName
        end)
        
        function findPlayer(playerName)
        		for i,v in pairs(playerList:GetChildren()) do
        			if playerName == v.Name then
        				return v
        			end
        		end
        		return false
        end
        
    [/code]
    
    Located within ServerScriptService:
    [code] 
        UpdateGUI2.OnServerEvent:Connect(function(player, playerName)
        	UpdateGUI2:FireAllClients(playerName)
        end)
        
    [/code]
    
    Let me know if anybody sees anything wrong with it. Like I said, everything works fine except for that.

To which @ThoseNamesAreGood (lua) replied

    So if I understand correctly, its cloning the same name twice into a UIGrid?

To which @WarioSvug (WarioSvug) replied

    Yes, it's cloning the same name twice into the scrolling frame. It appears that the FireAllClients is doing it. It's supposed to clone twice, but for whatever reason, it's cloning twice for everybody's screen rather than just cloning once for 2 different people's screen

Then @TheSingularFungi (Fungi) said

    [code]
        for i,v in pairs(game.Players:GetChildren()) do 
        -- code
        end
        
    [/code]
    
    Do the clone stuff in this script. It will clone once for each player in game.

To which @ThoseNamesAreGood (lua) replied

    Because your cloning it twice for each client i'm pretty sure (Which you've already pointed out).
    
    Just send a event to the server then from there do a loop like this:
    [code] 
        for i,v in pairs(game.Players:GetPlayers()) do
           -- Create a instance and parent it to v's PlayerGui.
        end
        
    [/code]

Then @WarioSvug (WarioSvug) said

    Ah man, I was really hoping to avoid that. I'll give it a shot and get back to you.

@TheSingularFungi (Fungi) replied

    I just said that. xD. We're both very clever.


{'source': 'discourse', 'url': 'https://devforum.roblox.com/t/object-clone-amount-based-on-amount-of-players-in-the-game/1261212', 'title': 'Object Clone Amount Based On Amount Of Players In The Game', 'views': 1968, 'has_accepted_answer': True, 'word_count': 610, 'like_count': 0, 'reply_count': 5, 'participant_count': 3, 'posts': 7, 'tags': 'scripting', 'author': '@WarioSvug (WarioSvug)', 'participants': '@WarioSvug (WarioSvug), @ThoseNamesAreGood (lua), @TheSingularFungi (Fungi)', 'image_url': [None], 'created_at': '2021-05-29T14:46:20.999Z', 'last_posted_at': '2021-05-29T15:21:21.233Z'}