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