hello! i want players to sit in a random seat but i keep getting this error. idk what im doing tbh. ty!
problem:
local randomSeat = seat[math.random(1, #seatFolder)]
script:
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
local seatFolder = workspace.tableModel.seatFolder
local hum:Humanoid = c.Humanoid
for seatName, seat:Seat in ipairs(seatFolder:GetChildren()) do
if seat:IsA("Seat") then
local randomSeat = seat[math.random(1, #seatFolder)]
if randomSeat:GetAttribute("occupied") == false then
c:PivotTo(randomSeat.CFrame* seatOFFSET)
wait(.5)
randomSeat:Sit(hum)
if randomSeat.Occupant then
randomSeat:SetAttribute("occupied", true)
randomSeat:SetAttribute("playerName", randomSeat.Occupant.Parent.Name)
end
break
end
end
end
end)
end)
hey man, thanks for ur response. basically my “occupied” thing is an attribute right and ive got this table with a load of seats. i just want it so that i wont be sitting in the same place every time. is there a way to do that?
Basically seat.Occupant can have 2 values. A nil value where nothing is sat in the seat. Or a value of displaying what is sat in the seat. In your case a player the value of seat.Occupant would be humanoid.
So instead of if randomSeat:GetAttrivute(“occupied”) == false then …
do
local humanoid = randomSeat.Occupant
if humanoid then...
When there is no player in the seat, humanoid will be false and therefor the if statement will be false.
hey klm,
thank u 4 ur response. i figured it out eventually with a bit of help from this post so credits to him but tysm 4 ur help:
solution:
local seatOFFSET=CFrame.new(0,2,0)
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
local seatFolder = workspace.tableModel.seatFolder
local hum:Humanoid = c.Humanoid
local randomSeat = seatFolder:GetChildren()[math.random(1, #seatFolder:GetChildren())]
if randomSeat:GetAttribute("occupied") == false then
c:PivotTo(randomSeat.CFrame* seatOFFSET)
wait()
randomSeat:Sit(hum)
if randomSeat.Occupant then
randomSeat:SetAttribute("occupied", true)
randomSeat:SetAttribute("playerName", randomSeat.Occupant.Parent.Name)
end
end
end)
end)
end