Problems with client-server

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShopFolders = script.Parent
local objectUIsFolder = ReplicatedStorage.ObjectUis
wait(2)

local function cloneFrames()
	for _, folder in (objectUIsFolder:GetChildren()) do
		local scrollingFrameShop = ShopFolders:FindFirstChild(folder.Name)
		for _, frame in (folder:GetChildren()) do
			if frame:IsA("Frame") then

				local clonedFrame = frame:Clone()
				clonedFrame.SelectBTN.SelectBTN.Text = "Buy"
				clonedFrame.Parent = scrollingFrameShop
-- I think it need to be on client, but how I can do it without knowing player, and I cant fire(I think) because it will be fired 100+ times
				clonedFrame.SelectBTN.SelectBTN.MouseButton1Click:Connect(function()
					local RS = in the player. What I can do?
					local CurrectBalance = RS.Value
					local CurrectCost = Cost.Value
					if CurrectBalance < CurrectCost then return end
					RS.Value -= CurrectCost

					clonedFrame.SelectBTN.SelectBTN.MouseButton1Click:Connect(function()
						local CurrectBalance = RS.Value
						local CurrectCost = Cost.Value
						if CurrectBalance < CurrectCost then return end
						RS.Value -= CurrectCost

						local InventoryClonedFrame = frame:Clone()
						local InventoryFolders = Player.PlayerGui.Inventory.Folders
						InventoryClonedFrame.Parent = InventoryFolders:FindFirstChild(folder.Name)

						InventoryClonedFrame.SelectBTN.SelectBTN.MouseButton1Click:Connect(function()
							Player.Character.Obj.Value = InventoryClonedFrame
						end)
					end)

				end)
-- I think it need to be on client, but how I can do it without knowing player, and I cant fire(I think) because it will be fired 100+ times
			end
		end
	end
end

cloneFrames()

My question is in code

set RunContext of script to client

Nonsense. I need part of this script to be 100% on the server.

then set RunContext to server

//////////////////////////////////

What the hell

Why is there a connection inside a connection inside a connection inside a loop inside a loop?

Because I need to get all instances of all classes, logically

clonedFrame.SelectBTN.SelectBTN.MouseButton1Click:Connect(function()
	local CurrectBalance = RS.Value
	local CurrectCost = Cost.Value
	if CurrectBalance < CurrectCost then return end
	RS.Value -= CurrectCost

	clonedFrame.SelectBTN.SelectBTN.MouseButton1Click:Connect(function()
		local CurrectBalance = RS.Value
		local CurrectCost = Cost.Value
		if Cu...

PLEASE don’t make a new connection inside of another one, it will just constantly stack the signals and could destroy the game performance-wise if clicked enough times!

Could you tell us a little more information? eg.

  • Does the button have to be on the server?
  • What is this script parented to?

You can see “the script is working”. Alas, so far only 1 person is playing. Please read this post

And also, after watching the video, you will see what the script is attached to

And yet, I can’t get rid of these loops due to the fact that if I do, I’ll get rid of the practicality of the code completely. Well, if I do this, there will be more than a thousand lines in the code

CollectionService is made for this. Nesting a connection in a connection can cause memory leaks. Instead, just loop through all of the Instances you need to connect that are tagged.

1 Like