Trying to delete a frame for everyone which isn't visible to the server

So I have this frame in replicated storage, whenever a button is clicked, it fires an event which then uses :FireAllClient() to clone the frame in replicated storage then parent it to the individual playerGuis. This happens multiple times throughout the game meaning there’s multiple with the same name. There’s something the player can do which causes those frames to go invisible, but it won’t work because the frames aren’t visible to the server. How can I destroy 1 single frame for everyone when it’s not visible to the server?

It would be visible to the client. Another FireAllClient could remove the frames. If you are worried about keeping track of the frames to get rid of, store the frame locations in a table in that LocalScript.

1 Like

Sorry, not too sure on how I’d do that, could you explain?

I don’t know what your current setup is, but the steps are pretty easy:

  1. declare an empty table in the localscript:
local framelist = {}
  1. when you create the frame, add it to the table:
framelist[#framelist +1] =  frameinstance --whatever you called the frame while cloning it
  1. to later delete all frames:
for i,singleframe in pairs [framelist] do
   singleframe:Destroy()
end
  1. or if you want to delete a specific frame, you need to pass some sort of identifier (eg frameID) from the server
framelist[frameID] =  frameinstance 
framelist[frameID]:Destroy()

I am not 100% sure on the code to destroy a part from a table, as it has given me trouble in the past.

1 Like

Going off of basically what GolgiToad said, I created a table on the client that holds all of the frames and their respective ID that was created by the server. I’m not able to test the script but this will at least give you a starting point.

Edit: added tonumber() to buttonscript

--Button script

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.FinishOrder:FireServer(tonumber(script.Parent.Parent.Name))
end)


--Script inside ServerScriptService

local OrderNumber = 0

finishOrder.OnServerEvent:Connect(function(player)
	OrderNumber += 1
	currentOrderAmount.Value -= 1
	print(OrderNumber)
	finishOrder:FireAllClients(OrderNumber)
end)


--Localscript

local TableOfFrames = {}

finishOrder.OnClientEvent:Connect(function(OrderNumber)
	for i = 1, #TableOfFrames do
		if TableOfFrames[i][1] == OrderNumber then
			TableOfFrames[i][2]:Destroy()
			table.remove(TableOfFrames, i)
		end
	end
end)

addOrder.OnClientEvent:Connect(function(OrderNumber)
	local uiElementClone = game.ReplicatedStorage.uiElement:Clone()
	uiElementClone.Name = OrderNumer
	--Set parent of uiElementClone
	local KeyToInsert = {OrderNumber, uiElementClone}
	table.insert(TableOfFrames, KeyToInsert)
end)
2 Likes