Hello! I am trying to make a train system, and for some reason I am getting this error.
ServerScriptService.Main.TrainSuperClass:19: attempt to call a nil value
SuperTrainClass Script
local TrainSuperClass = {}
TrainSuperClass._index = TrainSuperClass
local TweenService = game:GetService('TweenService')
function TrainSuperClass.new(TrainModel, Nodes)
local Train = {}
setmetatable(Train, TrainSuperClass)
Train.Nodes = Nodes
Train.TestModel = TrainModel
Train.Node = 1
coroutine.wrap(function()
wait(1)
Train:Setup()
end)()
return Train
end
function TrainSuperClass:Setup()
if not self.Nodes:FindFirstChild("Node"..self.Node) then
warn("Cannot find Node"..self.Node)
return
end
self.Train = self.TestModel:Clone()
self.Train.Parent = workspace
local All = self.Train:GetChildren()
for A = 1,#All do
if (All[A].Name ~= self.Train.PrimaryPart and All[A]:IsA("BasePart")) then
local NewWeld = Instance.new("Weld")
NewWeld.Name = "Weld"
NewWeld.Part0,NewWeld.Part1 = All[A],self.Train.PrimaryPart
NewWeld.C0 = All[A].CFrame:inverse()
NewWeld.C1 = self.Train.PrimaryPart.CFrame:inverse()
NewWeld.Parent = self.Train.PrimaryPart
end
end
self.Train:SetPrimaryPartCFrame(self.Nodes:FindFirstChild("Node"..self.Node).CFrame + Vector3.new(0, self.Train.PrimaryPart.Size.Y/2,0))
self:Move()
end
function TrainSuperClass:GetTime(Distance)
return Distance / self.Speed
end
function TrainSuperClass:Move()
end
function TrainSuperClass:Stop()
self.Node = 1
self:Setup()
end
return TrainSuperClass
TrainClass Script
local Sp = script.Parent
local Main = Sp.Parent
local TrainSuperclass = require(Main.TrainSuperClass)
local TrainClass = {}
TrainClass._index = TrainClass
setmetatable(TrainClass, TrainSuperclass)
function TrainClass.new(...)
local self = TrainSuperclass.new(...)
setmetatable(self, TrainClass)
self.Speed = 40
end
return TrainClass
Train1 Script
wait(1 + math.random())
local Sp = script.Parent
local Main = Sp.Parent
local Classes = Main.Classes
local Train1 = require(Classes.TrainClass)
Train1.new(Main.Train, game.Workspace.Nodes)
I am not asking for the whole code, I am just trying to figure out why I am getting this error, so I can fix it my self.
This is the ServerScriptService
Note: I am using Lukas tutorial for this: Here