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.