I have a LocalScript called UIHandler and a ModuleScript called UISettings in the same folder.
I want to create an ImageButton and ImageLabel using the settings in UISettings. The script works when I just add the data for the ImageButton and ImageLabel to the LocalScript but not when I call it from the ModuleScript.
– Local Script
local util = require(script.Parent:WaitForChild(“Utilities”))
local UISettings = require(script.Parent:WaitForChild(“UISettings”))
function CreateMobileChat()
local test = util.Create(“ImageButton”)({
UISettings.MobileHideChatIconButton
})
local test2 = util.Create(“ImageLabel”)({
UISettings.MobileHideChatIconImage
})
test2.Parent = test
return test
end
CreateMobileChat().Parent = game.Players.LocalPlayer.PlayerGui.MainGUI.TopBar
– ModuleScript
local module = {}
local util = require(script.Parent:WaitForChild(“Utilities”))
module.Chat = {
}
module.MobileChat = {
}
module.MobileHideChatIconButton = {
Name = “ChatVisible”,
Size = UDim2.new(0, 50, 0, 36),
Image = “”,
AutoButtonColor = false,
BackgroundTransparency = 1,
}
module.MobileHideChatIconImage = {
Name = “ChatVisibleIcon”,
Size = UDim2.new(0, 28, 0, 27),
Position = UDim2.new(0.5, -14, 0.5, -13),
BackgroundTransparency = 1,
Image = “rbxasset://textures/ui/Chat/ToggleChat.png”,
}
return module
– Utility Function I’m using if that helps
function util.Create(instanceType)
return function(data)
local obj = Instance.new(instanceType)
for k, v in pairs(data) do
if type(k) == ‘number’ then
v.Parent = obj
else
obj[k] = v
end
end
return obj
end
end
–
Now it creates the ImageButton perfectly fine if I do this:
local test = util.Create(“ImageButton”)({
Name = “ChatVisible”,
Size = UDim2.new(0, 50, 0, 36),
Image = “”,
AutoButtonColor = false,
BackgroundTransparency = 1,
})
I want it to do the same thing but using this line of code:
local test = util.Create(“ImageButton”)({
UISettings.MobileHideChatIconButton
})
It doesn’t return the table the way I want it to though.