Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to code a script inside another script, not working..??

Asked by 6 years ago
Edited 6 years ago

Hello, I am making an inventory system and I am trying to make a script in a script so this is what I am trying to do:

-- lets start...
-- the frame holds 25 imagebuttons
function MakeFrames()
    local HowManyFrames = 10
    local b = 0
    repeat
        local addValue = UDim2.new(b,0,0,0)
        local il = Instance.new("ImageButton", script.Parent)
        il.Size = UDim2.new(0.04, 0,0.845, 0)
        il.Position = UDim2.new(0,0,0,0) + addValue
        b = b + 0.04
        HowManyFrames = HowManyFrames - 1
                local NEWSCRIPT = Instance.new("Script", il)
                NEWSCRIPT.script = "print(b.Value)"
    until HowManyFrames == 0
-- replicated
end

MakeFrames()

The error is on line 13 and 14 , script is not a valid member of script, what can I do?

0
Correct me if I am wrong but you named the new script "NEWSCRIPT", and not script? So you'd call it using 'il.NEWSCRIPT' and not "il.script" T0XN 276 — 6y
0
Still, I don't exactly understand why you've made your system like this? Care to explain? T0XN 276 — 6y
0
You cannot set a source of a script, without command bar permissions or plugin permissions. hiimgoodpack 2009 — 6y
0
So wait, I fixed what T0XN said... The script is to create imagebuttons in a frame and insert a whole new script with a code i want in it, I will have to code the code but I am trying to figure out a way to do that... greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The error you are encountering is because there is no script property of scripts. There is a Source, but you cannot assign to that (or access it what-so-ever)..

No matter what you wish to accomplish, you shouldn't need to create scripts within scripts (which requires the use of 'loadstring'; it's server-side only and so not good for GUIs). You can :Clone() a pre-existing script (and parent it where-ever you like) or you can manage a table of ImageButtons (or whatever you want) all from one script (I thoroughly recommend doing this). ex:

for i = 1, 25 do
    local imageButton = Instance.new("ImageButton")
    imageButton.Size = UDim2.new(0.04, 0, 0.845, 0)
    imageButton.Position = UDim2.new(0.04 * (i - 1), 0, 0, 0)
    imageButton.Parent = script.Parent
    imageButton.MouseButton1Down:Connect(function(x, y)
        print("Image button #" .. i .. " clicked at", x, y)
    end)
end

The nice thing with putting it all in one script is that the code can use functions defined in the current script.

0
You can, but not the way he wants to. hiimgoodpack 2009 — 6y
0
so i have to create a totally different script and clone it then put it in the text button? greatneil80 2647 — 6y
0
You can, but I still recommend keeping it all in one script. I've shown a simple example of how to do that in the post (which I just updated). chess123mate 5873 — 6y
Ad

Answer this question