Code issues - Frame isnot cloning for all Team 1 players

Hi! I’ve been having issues with this code for days now. I need to clone the template with the data from the customer team who pressed the button, and then display this cloned template to all Team 1 players. Does anyone know what I’m doing wrong?

The template is not cloning for Team 1 players, it’s only cloning for the player who pressed the button. What’s wrong with my code?

localscript:

-- Connect click event for yes request order button
buttonYesRequestOrder.MouseButton1Click:Connect(function()
	-- Get the selected items
	local selectedItems = {}
	for _, button in ipairs(clickedButtons) do
		-- Use the buttonNames table to get the item name
		local itemName = buttonNames[button.Name]
		if itemName then
			table.insert(selectedItems, itemName)
		end
	end

	-- Get the order data
	local orderData = getOrderData()
	local totalPrice = calculateTotalPrice()
	local scrollingFrame = Players.LocalPlayer.PlayerGui.OrdersList_UI.Background.ScrollingFrame

	if totalPrice > 0 then
		resetOrder()
		ReplicatedStorage.remoteEvents:WaitForChild("close_OrderGUI"):FireServer()
		toggleLoadingOrderSent(true)
		wait(3)
		toggleLoadingOrderSent(false)
		wait(0.2)

		local playerTeamName = Players.LocalPlayer.Team and Players.LocalPlayer.Team.Name
		if playerTeamName == "Customer" then
			local clonedTemplateEvent = game:GetService("ReplicatedStorage").ordersListTemplates:WaitForChild("clonedTemplateEvent")
			-- Pass order data as parameters to clonedTemplateEvent:FireServer()
			clonedTemplateEvent:FireServer(orderData.username, selectedItems[1], selectedItems[2], totalPrice)
		else
			print("You are not in Customer Team.")
		end
		resetButtonColor() -- Reset button color
	else
		warn("There are no items in the order or a template already exists.")
	end
end)

server-script:

local clonedTemplateEvent = game:GetService("ReplicatedStorage").ordersListTemplates:WaitForChild("clonedTemplateEvent")

clonedTemplateEvent.OnServerEvent:Connect(function(player, username, item1, item2, totalPrice)
	local frameTemplate = game:GetService("ReplicatedStorage").ordersListTemplates.Template
	local textLabelTemplate = frameTemplate.TextLabel

	-- Format the text for the textLabel
	local formattedText = "Order by " .. username .. ": " .. item1 .. ", " .. item2 .. ". Your earnings: $" .. totalPrice .. " CB"

	if player.Team and player.Team.Name == "Team 1" then
		-- Clone the frameTemplate into the ScrollingFrame
		local OrdersList_UI = player:WaitForChild("PlayerGui"):FindFirstChild("OrdersList_UI")
		OrdersList_UI.Enabled = true

		local clonedFrame = frameTemplate:Clone()
		clonedFrame.Parent = OrdersList_UI.Background.ScrollingFrame

		-- Update the textLabel with formatted text
		clonedFrame.TextLabel.Text = formattedText
	else
		warn("Player is not in Team 1.")
	end
end)

On the server side, you need to loop through all players on the team and apply the cloning and updating logic. Currently you have:

if player.Team and player.Team.Name == "Team 1" then ...

However, if you want to apply this to the whole team you need to do:

for _, plr in game.Players:GetPlayers() do
    if plr.Team and plr.Team.Name == "Team 1" then
        ...
    end
end
2 Likes

Oh my goodness! I never thought it would be that, and I was racking my brain thinking of different ways to do it. Thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.