I’m making a generic billboard GUI, which will get re-used by multiple pieces of furniture in the game. The player interacts with a Prox, whose Local Script (1) Clones the Options GUI. (2) Passes it a list of customized options. (3) It then shows itself. (4) Invoke callbacks from those options.
I can’t work out how to do step (2): Passing the data to the cloned script from a different Local Script. In the billboard is a localScript:
function setup(pTitle:string, pOptions, pCallback)
script.Parent.frame.lblTitle.Text = pTitle
-- sets up the list of clickable options in an autosize frame
-- selected options invoke a callback(optionId)
-- all good, all easy, all tested in the Workspace
-- How do I CALL this function after cloning its parent?
end
I tested the script on a fixed GUI on a Billboard in Workspace, and now its all moved to PlayerStarterGui and hidden, ready to be cloned. But after cloning, how do I ‘call’ its functions in its script, or otherwise, pass data to it?
local lBillboard = plrGui.optionsTemplate:Clone() -- Cloned.
lBillboard.script.Disabled = false
-- Now, pass it the information it needs:
lBillboard.setup ("Title", {option1,option2}, myCallback) --HOW?
lBillboard.parent = plrGui
Obviously, there is no such thing as .setup() , this is just as example of what I would do next, if I could find a way.
Using a Module Script works, but something about this is worrying me!
local lBillboard = plrGui.optionsTemplate:Clone() – Cloned.
local lBBModule = require(lBillboard.mScript)
lBBModule .setup(“title”) – yay
Although it works… I’m worried that this is weird and/or bad practice. I’ve not seen any other forum posts or examples that do this kind of thing!
I can’t use an event, because, each time I clone it, all the resultant GUIs will be listening to the same event, and I won’t be able to target a particular one.
I’m trying to make it self-contained, so that the script and the billboard can all be together, so it’s easy to copy it all from project-to-project in the future.
An alternative is to create the whole billboard & GUI elements purely in code. But it’s a LOT to write out and difficult to do design changes without physically looking at it.
There’s no other posts about this, which makes me think my entire approach is wrong! What’s the right approach?