What i want to achieve:
Random amount of TextButtons created and parented to a ScrollingFrame. With in the TextButton is a cloned script “ButtonScript”.
Amount of TextButtons are the amount of all scripts in game.
I am also trying to keep the TextButton script separate from the main script.
Summary
main script is the “Refresh” button
“Script1” is the TextButton so is “Script2” etc
“ButtonScript” is cloned into all the TextButtons
The issue:
The issue still remains that any cloned script after the plugin refreshes will not run.
And if a script is disabled then re-enabled after the plugin refreshes it will not run.
-- main script
--[[
put this in plugin
]]
wait(1)
print("Create Script")
local run = script.run
local run_Clone = run:Clone()
run_Clone.Name = "Running"
run_Clone.Disabled = false
run_Clone.Parent = script
-- run script
--[[
parent this to main script
]]
print(script.Name)
I have looked through the devform and could not find a post related to this issue.
Whatever you’re describing is pretty abstract. A few more details would be very helpful. What are all these TextButtons for? What purpose do they serve? Is it an editor of some kind? What’s this plugin even do? Is it even relevant that this is a plugin?
It sounds like you ought to use a ModuleScript for this. Or, rather, whatever is instantiating your buttons should connect to their MouseButton1Click events, rather than a script within them.
Just like @Ozzypig said you can simply connect the MouseButton1Click event whenever you create a new textbutton.
For example:
function CreateNewButton() -- Pretend this is your script thats creating random amounts of text buttons
local NewButton = Instance.new("TextButton");
NewButton.Size = UDim2.new(0,200,0,50);
NewButton.Parent = script.Parent.ScrollingFrame; -- Parent it to the scrolling frame, etc
-- In the same script right after you create the textbutton, you can connect MouseButton1Click event to the created button
NewButton.MouseButton1Click:Connect(function() -- Connect the event to the new button
print("You have clicked the button!!");
-- do what you want here
end);
end;
while wait(3)do -- Lets say your creating text buttons via while loop (please don't actually do this tho)
CreateNewButton();
end;
This is just a rough idea of how you would do it. Hopefully it gives you some insight of what to do!