vladxh
(DudeXh)
January 4, 2023, 5:21pm
#1
in my game i have a lot of variables that have assigned the same value like this
local big = 32
local var1 = game.workspace.part1
local var2 = game.workspace.part2
local var3 = game.workspace.part3
local var4 = game.workspace.part4
and when i assign a value
var1.size = big
var2.size = big
var3.size = big
var4.size = big
what i wanna know is if there is any way theres to make this take less lines of code and make it look better
i have already tried for loops like this
bigVar = {var1,var2,var3,var4}
for i = 0,4,1 do
bigVar[0+i].size = big
end
but it did nothing i didnt get a error but it also didnt work prob im doing something wrong, if you have any sugestions please tell me
1 Like
Dev_Sie
(Sie)
January 4, 2023, 5:32pm
#2
why do you have multiple variables for the same part?
The main issue I found is that your loop starts at 0. Roblox’s index starts at 1, not 0. Try this loop instead.
bigVar = {var1,var2,var3,var4}
for i,v in pairs(bigVar) do
v.size = big
end
The problem with your code is that in the first iteration, bigVar[0+i] is bigVar[0]. This is because, as @CodeJared stated, Lua’s index starts at 1, not 0. Therefore, you should either change it to
bigVar[1+i]
or
for i = 1, 4, 1 do
.
Here’s the code using the latter method.
bigVar = {var1,var2,var3,var4}
for i = 1,4,1 do
bigVar[0+i].size = big
end
This should work, do let me know if it doesn’t.
1 Like
You can put the parts in a folder and do
for _, part in workspace.Folder:GetChildren() do
for i = 1, 4 do
part.Size = Vector3.new(i,i,i)
end
end
2 Likes
vladxh
(DudeXh)
January 4, 2023, 7:43pm
#6
they are the same part forgot to add that
Did any of the solutions we’ve posted work?
system
(system)
Closed
January 18, 2023, 7:45pm
#8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.