CollectionService Script Error

Hello, I am having problems with a script, it utilizes CollectionService so I can keep everything organized and not messy while I develop.

I am trying to make moving platforms with TweenService and everytime I test it, I always have this error pop up in the output:

20:09:17.963 ServerScriptService.Server.Platform.Movement:21: attempt to index number with 'CFrame' - Server - Movement:21

I don’t know what to do as I am very confused on what this means, I’ve tried looking for solutions on the forum but no luck.

Here is a Module Script:

local Movement = {}

local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

function Movement.Tween()
	for Part, _ in pairs(CollectionService:GetTagged("Movement")) do
		
		local tweenInfo = TweenInfo.new(

			3,
			Enum.EasingStyle.Cubic,
			Enum.EasingDirection.InOut,
			-1,
			true

		)

		local tween = TweenService:Create(Part, tweenInfo, {
			CFrame = Part.CFrame * CFrame.new(-30, 0, 0)
		})

		tween:Play()

		local lastPosition = Part.Position

		RunService.Stepped:Connect(function(_, deltaTime)
			local currentPosition = Part.Position
			local deltaPosition = currentPosition - lastPosition

			local velocity = deltaPosition / deltaTime
			Part.AssemblyLinearVelocity = velocity

			lastPosition = currentPosition
		end)
	end
end

return Movement

And the Server Script:

local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local MovementModule = require(script:WaitForChild("Movement"))
local ElevationModule = require(script:WaitForChild("Elevation"))

for Part, _ in pairs(CollectionService:GetTagged("Movement")) do
	MovementModule.Tween(Part)
end

for Part, _ in pairs(CollectionService:GetTagged("Elevation")) do
	ElevationModule.Tween(Part)
end

This is pretty much the only thing I’m having trouble with, I would appreciate the help I can get from this situation.

In this case, the first thing that pairs returns is a number; the tagged instance will be second. Try replacing Part, _ with _, Part.

pairs documentation

To go more in depth, it means you were trying to do something like:

number.CFrame

Ever seen those errors where it goes like: attempt to index nil with __

That’s because nil would be the type you are trying to find a member of. But since nil has no members, and is a type, will reach out with this error.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.