Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

A script that makes variables that are numbered after each trigger?

I need help with a gui im making, and decided to instead of making Frame 1,2,3,4, I was wondering if someone knew how to make a function that makes a new variable of the same text but numbered differently, a example, I active a function called, " NewFrame ", it makes a new frame but makes a variable for the frame called, "NewFrame1" and i was wondering if you were able to then trigger the function again, for it to make a entire new frame, thats the named as a variable, "NewFrame2" then the number will rise up one after each trigger of the function.Something along the lines of this code:

FramesMade = 0
function NewFrame()
	FramesMade = FramesMade + 1
	NewFrame[FramesMade + 1] = Instance.new("Frame")
end
NewFrame()
wait(2)
 NewFrame1:Destroy()
wait(1)
NewFrame()
wait(2)
 NewFrame2:Destroy()

2 comments

0

use for i = 1,number do

0

Oh that works? Ill try

1 answer

I think you are looking for something like this (I used return because I didn't know what was your usage of frame so you can set parent outside of the function)

local createdframes = 0

local createFrame = function()
	local frame = Instance.new("Frame")
	frame.Name = "NewFrame"..createdframes
	createdframes = createdframes+1
	return frame
end

local new = createFrame()
new.Parent = game.Workspace -- Example of parent
wait(2)
local new2 = createFrame()
new2.Parent = game.Workspace

This discussion is preserved as it was. New answers, comments, and votes are closed.