Attempting train reverse system

I’m trying to make it so that when you click a button, the train is controlled from the other side. Currently in the system I am using there was a reverse feature made but not completed and I am trying to complete it.

So there was a function built into the system and i’ve tried to call it but it’s giving me an error even though in my logic the error shouldn’t be happening.

function LocalModule:ForceReverse()
	print("Called")
	if self.Properties.canReverse then
		print("Exists")
		if self.Properties.canReverse == true then
			self.Properties.reversed = true
			local seat = self.Properties.vehicleSeat
			if self.Properties.revVehicleSeat then
				seat = self.Properties.revVehicleSeat
			end
			self:SendPlayerMessage("base", {
				action = "reversed",
				seat = seat
			})
			self.Properties.Event:Fire("base", {class = self, action = "Reversed", seat = seat})
			return true
		end
		if self.Properties.reversed == true then
			self.Properties.reversed = false
			self:SendPlayerMessage("base", {
				action = "reversed",
				seat = self.vehicleSeat
			})
			self.Properties.Event:Fire("base", {class = self, action = "Reversed", seat = self.vehicleSeat})
			return true
		end
	end
	return false
end

It’s throwing this error: “ServerStorage.TrainSystem.TrainModule:331: attempt to index nil with ‘canReverse’”
Even though here it’s defined:

function TrainModule.new(trainModel, data)
	local classSelf = {}
	setmetatable(classSelf, LocalModule)
	classSelf.Properties = {}
	classSelf.Properties.trainModel = trainModel
	classSelf.Properties.rawData = data
	classSelf.Properties.currentDriver = nil
	classSelf.Properties.reversed = false
	classSelf.Properties.canReverse = false

Apologies if this was written badly but it’s my first support post on the dev forum.

1 Like

Try renaming classself to self

Who is the caller for the function that has this error? Can you post that code?

1 Like

I’ve found a workaround by inverting the velocity. Thanks to all who tried to help.

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