expanding functionality for a ‘currently wearing’ menu so that players can take off roblox accessories, I have to get the server to do some things like getting names for the accessories so I can delete them but for some reason every time I open the ‘currently wearing’ menu again it makes duplicates of the accessory UI buttons despite me clearing the scrollframe every time the GUI is closed.
after a bit of testing it looks like (at least from the perspective of the console) that the server code is using fireclient() multiple times even though the loop right above it is closed, the amount of times it loops increases every time I open the menu
clientside
local Accessories = plr.Character.Humanoid.HumanoidDescription:GetAccessories(true) --Gets accessories from humanoid description
ReplicatedStorage.AccEvents.GetRBXAccessories:FireServer(Accessories) --sends accessory info to server (see serverside code)
ReplicatedStorage.AccEvents.SendRBXAccessories.OnClientEvent:Connect(function(accs) --recieves the updated information from the server
print(accs)
for i, d in next, accs do
if plr.Character:FindFirstChild(d[2]) ~= nil then
local NewButton = script.Item:Clone()
NewButton.Parent = ScrollFrame
NewButton.Image = 'rbxthumb://type=Asset&id='..d[1]..'&w=150&h=150'
NewButton.ItemV.Value = d[2]
NewButton.RemoveB.ImageButton.MouseButton1Down:Connect(function()
ReplicatedStorage.AccEvents.ClearAccessories:FireServer(NewButton.ItemV.Value)
NewButton:Destroy()
end)
end
end
end)
Serverside
game.ReplicatedStorage.AccEvents.GetRBXAccessories.OnServerEvent:Connect(function(plr, Accessories)
local Accs = {} --creates clean table for new info
for i,d in next, Accessories do
local tab = {} --makes a subtable
local Accessory = insert:LoadAsset(d.AssetId)
--local acccc = Accessory:GetChildren()
table.insert(tab, d.AssetId) --inserts ID to subtable
table.insert(tab, Accessory:FindFirstChildOfClass('Accessory').Name) --inserts name to subtable
table.insert(Accs, tab) -- inserts subtable to main table
Accessory:Destroy()
end
print(Accs)
game.ReplicatedStorage.AccEvents.SendRBXAccessories:FireClient(plr, Accs) --sends updated info back to client
local Accs = {} --clears main table for next use......not neccessary, but just in case
end)
hopefully I haven’t screwed up the formatting
edit: I’ve put a temporary patch on the problem by not making new UI if it already exists, but I would like a permanent solution so the server isn’t doing more than necessary and I can avoid this problem in the future