For example we have script to render gui slots for inventory:
local Render = {
["Displayed"] = {}
}
local player = game:GetService("Players").LocalPlayer
local System = script.Parent.Parent
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Modules
local ItemData = require(ReplicatedStorage.ObjectsData.ItemsData)
-- Gui
local Inventory = player.PlayerGui:WaitForChild("Inventory").Main
local DisplayItems = Inventory:WaitForChild("SelectedSection").Inventory.Display.Items --/ sometimes it doesn't load soo use WaitForChild
local WeightBar = Inventory:WaitForChild("SelectedSection").Inventory.WeightIndicator.Bar
-- Create new frame and set it's parent to displayed items folder
function Render:CreateItemFrame(Item: ValueBase): GuiBase
local NewFrame = System.Item:Clone()
NewFrame.Name = Item.Name
NewFrame.Image = ItemData[Item.Name].Image
if Item.ClassName == "IntValue" then NewFrame.Count.Text = Item.Value end
NewFrame.Parent = DisplayItems
return NewFrame
end
-- Updates item count
function Render:UpdateItemCount(Frame: ImageLabel, Item: ValueBase)
Frame.Count.Text = Item.Value
if Item.Value <= 0 then Frame.Visible = false else Frame.Visible = true end
end
function Render:UpdateWeightBarSize(Weight: number, MaxWeight: number)
local percent = Weight/MaxWeight
WeightBar.Size = UDim2.new(percent,0,1,0)
end
return Render
As you can see this script have 3 methoods, 2 of them are updating different parts of Gui, one is updating Item Count Frame, and second weight bar which shows how heavy this inventory is, the question is that is this bad practice to have function to perform 1 hardcoded task?