Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problem with RemoteEvents piling up..?

LOCAL

for i,instance in pairs (inventoryList:GetChildren()) do
		if instance:IsA("ImageLabel") then
			instance:Destroy()
		end
	end
	
	local remote = game.ReplicatedStorage.Assets.Remotes.Remote
	local guiFolder = game.ReplicatedStorage.Gui
	remote:FireServer("GetPlayerData")
	remote.OnClientEvent:Connect(function(data, dataType)
		if dataType == "SendData" then
			for key, value in pairs(spellModule) do
				for dataKey, dataValue in pairs(data.Spells) do
					if key == dataValue then
						local invSpot = guiFolder.InventorySpot:Clone()
						invSpot.Parent = inventoryList
						invSpot.Name = value.Name
						invSpot.Icon.Image = "rbxassetid://"..value.Image
						invSpot.ItemValue.Value = key
						
						local invHover = guiFolder.LoadoutEquip:Clone()
						invHover.Parent = invSpot
						invHover.Disabled = false
					end
				end
			end
		end
	end)
end

SERVERSCRIPTSERVICE SCRIPT

local remoteEvent = game.ReplicatedStorage.Assets.Remotes.Remote
remoteEvent.OnServerEvent:Connect(function(player, datatype)
	if datatype == "GetPlayerData" then
		remoteEvent:FireClient(player, GetData(player), "SendData")
	end
end)

My problem is that each time i click on the button that fires this function, it adds another.. RemoteEvent fire?- What i mean is; So i click it once, it works fine, it generates the Gui once, I click it again, and it generated 2 of the guis, I click it again, it generates 3, and so on.

How do I know its not just constantly adding more of the gui? Well, for one,,

if instance:IsA("ImageLabel") then
	instance:Destroy()
end

Secondly,, I previously had the OnClientEvent print the table, and it would print 3 tables, so somehow it's multiplying itself..

How would i fix this?? I've never run into something like this..

1 answer

I believe it's because you're not deleting the gui when it's done being shown. You just have a pile of Guis everytime you fire the event. That's why the number of guis increases by 1 each time.

1 comment

0

I am though, lines through 1-5.. also the fact that for a split second all the guis disappear, and then re-appear with 1 more

This discussion is preserved as it was. New answers, comments, and votes are closed.