How do you handle functions for multiple UI

so basically im a bit stuck at the moment. i’m trying to make my game modular but i’m not sure how to handle multiple UI’s that well. i have buttons like Shop, Inventory, Craft which will all have different functions but i can’t seem to connect the dots.

this is my UI Manager so far. i have my MouseEnter, MouseLeave, MouseButton1Click functions all in the one function which i call once in a local script. i’m probably doing this very badly but anyways. thanks i appreciate any help! :slight_smile:

function UIAnimator:TagUI()
	for _, instance in ipairs(PlayerGui:GetDescendants()) do
		if instance:IsA("GuiObject") then
			CollectionService:AddTag(instance, "AnimatableUI")
			--print("tag added to "..instance.Name)
		end
	end
end

function UIAnimator:AnimateUI()
	for _, guiObject in ipairs(CollectionService:GetTagged("AnimatableUI")) do
		if guiObject:IsA("GuiObject") then
			local guiObjectSize = guiObject.Size
			
			guiObject.MouseEnter:Connect(function()
				UIAnimator:SizeUp(guiObject)
				SoundManager:Play('Hover')
			end)
			
			guiObject.MouseLeave:Connect(function()
				UIAnimator:SizeDown(guiObject, guiObjectSize)
			end)
		end
		
		if guiObject:IsA("TextButton") or guiObject:IsA("ImageButton") then
			guiObject.MouseButton1Click:Connect(function()
				SoundManager:Play('Click')
			end)
		end
	end
end
1 Like

For handling multiple UIs, in my opinion, i suggest that you should put LocalScript inside each UI to do its own thing. It is easier to manage and debug (from my experience). You may use BindableEvent to fire when it is clicked to open, load, or update your UI. If that make sense.

2 Likes

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