Object Clone Amount Based On Amount Of Players In The Game

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.

  1. What is the issue? Include screenshots / videos if possible!

https://gyazo.com/b6e8b76df7bdf2c0bedf4f333ec79eb8

  1. 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.

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

Located within ServerScriptService:

UpdateGUI2.OnServerEvent:Connect(function(player, playerName)
	UpdateGUI2:FireAllClients(playerName)
end)

Let me know if anybody sees anything wrong with it. Like I said, everything works fine except for that.

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

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

for i,v in pairs(game.Players:GetChildren()) do 
-- code
end

Do the clone stuff in this script. It will clone once for each player in game.

1 Like

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:

for i,v in pairs(game.Players:GetPlayers()) do
   -- Create a instance and parent it to v's PlayerGui.
end
1 Like

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

I just said that. xD. We’re both very clever. :relieved: