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

'for' limit must be a number?

Asked by 5 years ago

So I made this script where it is supposed to slowly increase your size but it keeps giving me this error. Could someone help me?

    local NewSize = v.Size * 2
    local SizeNumber = tonumber(NewSize)
    if v.ClassName == "Part" or v.ClassName == "MeshPart" then
        for i = 0, SizeNumber, 1 do
            v.Size = i
        end
    end

Thanks in advance!

2 answers

Log in to vote
0
Answered by
ScuffedAI 435 Moderation Voter
5 years ago
Edited 5 years ago

Here's a list of problems with your code:

  • At line 2: You're trying to convert a vector3 value into a number.
  • At line 5: You're trying to set the the size value by using a number.
  • You might want to add a wait inside the for loop if you want it to slowly increase the size
local NewSize = v.Size * 2

-- this will become nil because roblox doesn't know 
-- how to turn a Vector3 value into a number
local SizeNumber = tonumber(NewSize) 

if v.ClassName == "Part" or v.ClassName == "MeshPart" then
    for i = 0, SizeNumber, 1 do

        -- this will throw error because it only accepts 
        -- Vector3 values and not a number.
        v.Size = i 

    end
end

How would we solve your problem? There's multiple of creative ways of achieving your goal. The first solution that comes into my mind is using TweenService.

TweenService has just one function, TweenService:Create, which takes information about the animation and generates the Tween object which can be used to play the animation. Note that Tweens can animate multiple properties at the same time.

The full documentation can be found here

In your case, we want to create tween which has propertyTable set to your NewSize variable.

Here's what the code would look like:

local TweenService = game:GetService('TweenService')
local NewSize =  v.Size * 2

if v.ClassName == "Part" or v.ClassName == "MeshPart" then
    local tweenInfo = TweenInfo.new(
        2, -- Amount of time it's going to take to complete the tween
        Enum.EasingStyle.Linear -- The tweening style
    )

    -- we create the tween and play it.
    TweenService:Create(v,tweenInfo,{
        Size = NewSize
    }):Play()
end

I highly encourage you to read through documentation if you find it difficult to follow along, because TweenService is service which makes a lot of your tasks easier.

I know I could've have gone into more detail about TweenService but I sadly didn't have enough time.

Ad
Log in to vote
0
Answered by 5 years ago

You should probably use while wait(number) do instead of for loops

0
Okay, I will try that. ScriptedEli 101 — 5y

Answer this question