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!
Here's a list of problems with your code:
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.
You should probably use while wait(number) do instead of for loops