I am working on rewriting the code for my game, The Room. It currently has a lot of bad practices, and I’m wondering what I should use in place of them. Currently, I have a collection of similar objects that behave the same way (for example, the GUI code below for the Home Screen). However, I know that there has to be a better way to calling the function for each individual object. I have considered using collection service, but I have heard a lot of debate as to whether I should use OOP or not. What would be the best strategy for this scenario? Any and all feedback is appreciated!
This is the code now.
local NewColor = Color3.new(0.545098, 0.545098, 0.545098) --Define Color Codes
local OldColor = Color3.new(1, 1, 1)
local function MouseEntered(GuiObject)
GuiObject.TextColor3 = NewColor
end
local function MouseLeaved(GuiObject)
GuiObject.TextColor3 = OldColor
end
PlayButton.MouseEnter:Connect(function()
MouseEntered(PlayButton)
end) --enact hovers
EndingsButton.MouseEnter:Connect(function()
MouseEntered(EndingsButton)
end)
UpdateLogButton.MouseEnter:Connect(function()
MouseEntered(UpdateLogButton)
end)
PlayButton.MouseLeave:Connect(function()
MouseLeaved(PlayButton)
end)
EndingsButton.MouseLeave:Connect(function()
MouseLeaved(EndingsButton)
end)
UpdateLogButton.MouseLeave:Connect(function()
MouseLeaved(UpdateLogButton)
end)
(This comes up a lot in my game. For example, I have a function for picking up toys, and for each individual toy, I call the function.