Attempt to call a table value

On this line: lua self:Connections() I get the error “attempt to call a table value.” However, I am unsure of the reason why / or at least workarounds. Any help would be appreciated. Thanks.

Code:

function Chair:Occupy(Humanoid: Humanoid)
	local Player: Player | nil = game.Players:GetPlayerFromCharacter(Humanoid.Parent)

	if not self.Occupied then
		self.Occupied = true

		Humanoid.Sit = true
		Humanoid.PlatformStand = true
		Humanoid.PlatformStand = false
		Humanoid.AutoRotate = false
		Humanoid.JumpPower = 0
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)

		if Player then
			Player.CameraMode = Enum.CameraMode.LockFirstPerson
		end
	end
end

function Chair:Exit(Humanoid: Humanoid)
	if self.Occupied then 
		self.Occupied = false

		Humanoid.Sit = false 
		Humanoid.PlatformStand = false 
		Humanoid.AutoRotate = true
		Humanoid.JumpPower = 40 
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)

		local Player: Player | nil = game.Players:GetPlayerFromCharacter(Humanoid.Parent)

		if Player then
			Player.CameraMode = Enum.CameraMode.Classic
		end

		self.Chair:SetAttribute("Reset", tick())
		print("Reset time:", self.Chair:GetAttribute("Reset"))

		self:Disconnects()

		if Player then
			Player.CharacterAdded:Connect(function(Character)
				local Humanoid = Character:WaitForChild("Humanoid")
				self:Connections()
				self:Occupy(Humanoid)
				self:LockCamera(Humanoid)
			end)
		end
	end
end

function Chair:Connections()
	self.Connections = {
		Added = self.Seat.ChildAdded:Connect(function(Child)
			if Child:IsA("Weld") then 
				local Character: Model = Child.Part1.Parent
				local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

				if Humanoid then 
					self:Occupy(Humanoid)
					self:LockCamera(Humanoid)
				end
			end
		end),

		Removed = self.Seat.ChildRemoved:Connect(function(Child)
			if Child:IsA("Weld") then 
				local Character: Model = Child.Part1.Parent
				local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

				if Humanoid then 
					self:Exit(Humanoid)
					self:UnlockCamera(Humanoid)
				end
			end
		end),

		AttributeChanged = self.Chair:GetAttributeChangedSignal("Reset"):Connect(function()
			print("Reset attribute changed")

			if self.Occupied then
				print("Player was occupied")

				local resetTime = self.Chair:GetAttribute("Reset")
				if resetTime and tick() - resetTime < 2 then
					-- Wait for 2 seconds before re-occupying the chair to avoid teleporting issues
					task.wait(2 - (tick() - resetTime))
				end

				local occupant = self.Seat:FindFirstChildOfClass("Humanoid")
				if occupant and occupant.Parent then
					self:Occupy(occupant)
					print("Player re-seated")
				end
			end
		end),

	}
end
1 Like

Your self:Connections() is calling from the InterrogationChair table and not from the Chair table (which is what you need)

also can do this instead of Player | nil
local Player: Player? = game.Players:GetPlayerFromCharacter(Humanoid.Parent)

2 Likes

You redefine the function after calling it

2 Likes

That fixed the error, but my code is broken regardless. If the player resets I want them to re-sit in the chair. Currently, that strait up does not work. Any suggestions to do this?

1 Like

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