Hello, after researching a lot and finding no answers. I’m wondering how can I use a “v” in a script? For example,
for i,v in pairs(script.Parent()) do
script.Parent = workspace.Folder.(v.Name)
end
Thank you in advance.
Hello, after researching a lot and finding no answers. I’m wondering how can I use a “v” in a script? For example,
for i,v in pairs(script.Parent()) do
script.Parent = workspace.Folder.(v.Name)
end
Thank you in advance.
V is the values of whatever your iterating over. EX, in a array where its [1,2,3], i is the index of the position where the values are stored and v is the value itself.
Edit: I think you mean ipairs not pairs since you used i,v “index,value”.
--Example 1
local Folder = game.workspace.ReplicatedStorage.SomeItems < your Folder
for i, v in pairs (Folder:GetChildren() do
print( i, v)
end
-- Will print anything inside of that Folder
-- Example 2:
local List = {
Potato = 0,
Carrot = 0,
Apple = 0,
Coins = 0,
Something = 0
}
-- Note that tables you don't
--use :GetChidren, because this is not an "Instance.new"
--( correct me if i said something wrong lol )
for i, v in pairs(List) do
print(i, v)
end
--Where [i] is [The Ingredient's Name]
--And [v] is [The amount]
for example, this will print everything inside that folder (childs)
you can use this in many ways, Tables, Getting some values from somewhere, etc
I know, it’s that I have a button that makes a frame turn visible. But, I want to make everything automated/from one script. But to this I don’t want to go through every object. So I use for i,v so I can loop through the frames. However, I can’t find the frame though when using the v. So I changed the button name to the frame to find the frame.
Thank you for your time.
Edit: What’s ipairs?
Pairs is used with dictionaries and ipairs with arrays.
I don’t think you need to loop through the frames. Normally you can just do something like this “Main.FrameName.Visible = true” depending on how you set it up.
But if I do that I probably need to do that for every frame. Is it possible to find the frame name using for i,v? If not that would work.
Yeah that would work but it would still iterate through everything until it finds it all. Just put an if statement in the for loop like “if v == “name”” to only apply changes to those frames.
for i,v in pairs(script.Parent:GetChildren()) do
v.Parent = workspace.Folder:FindFirstChild(v.Name)
end
Not sure if this is what you were trying to do.