OOP Tween is not functioning

Hello! I am currently making a script that tweens every part with the tag of “Part” using OOP.

My problem is that my tween function is saying:
unable to cast to dictionary

Here is my code:

local tweenService = game:GetService("TweenService")

local part = {}
part.__index = part

part.tweenTime = 2

function part:new(model)
	local newPart = setmetatable({}, self)
	newPart.__index = newPart
	newPart.Model = model
	
	return newPart
end

function part:tweenSize(properties)
	local tween = tweenService:Create(
		self.Model,
		TweenInfo.new(self.tweenTime, Enum.EasingStyle.Elastic, Enum.EasingDirection.In, -1, true, 0.5),
		properties
	)
	
	return tween
end

function part:startTween()
	local properties = self.Model.Size * Vector3.new(20, 20, 20)
	local tween = self:tweenSize(properties)
	tween:Play()
end

return part

Tagged code:

local collectionService = game:GetService("CollectionService")
local tagged = collectionService:GetTagged("Part")

local partModule = require(game:GetService("ServerScriptService")

for i, part in pairs(tagged) do
     local newPart = partModule:new(part)
     newPart:startTween()
end

If you can help, please reply :slightly_smiling_face:

The ‘properties’ (the tween’s goals) is supposed to be a dictionary, not a vector3. I’m not sure what you’re trying to tween, but if the size, for example, you’d have to do:
local properties = {Size = self.Model.Size * Vector3.new(20,20,20)}

Oh yeah, I forgot about that. I was focused on learning OOP and forgot about tweenservice stuff xD

Thanks.

1 Like