local List = {Vector3.new(3, 3, 3), Vector3.new(3, 3, 3), Vector3.new(3, 3, 3)}
local Max = 10
local Size = 0
for i, v in next, List do
Size = Size + (v).Magnitude
end
print(Size) -- 15
i want Size = Max but dont know how.
Please help me!
local List = {Vector3.new(3, 3, 3), Vector3.new(3, 3, 3), Vector3.new(3, 3, 3)}
local Max = 10
local Size = 0
for i, v in next, List do
Size = math.clamp(Size + v.Magnitude, 0, Max)
end
print(Size) -- 15
Changes:
for i, v in next, List do
- Size = Size + (v).Magnitude
+ Size = math.clamp(Size + v.Magnitude, 0, Max)
end
Before posting a thread in Scripting Support, please ensure you’ve read and met the guidelines first. Throwing a script onto Scripting Support and asking for help without completing bare minimum effort on your end is improper and poor use of the category.
Your issue was not clearly explained. My solution assumes that you wanted to cap your Size variable. If I took your help request at face value, I would say that you already had your solution right in the post - set the value of the variable Size to Max. I don’t know why you can’t do that in this case either. Your problem is very loosely explained - in fact, it isn’t at all.
There’s no indication that you’ve tried anything to fix your supposed problem or done searching yourself before posting this thread. It would be helpful to include those so we don’t waste time by posting something you’ve already tried before or something that doesn’t fulfil your request.
There’s a lack of details of any kind on this thread, plain and simple. Please do not throw scripts on Scripting Support and expect that people fix your code for you.