You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Make the script work (cant describe it really sorry.) -
What is the issue? Include screenshots / videos if possible!
Workspace.CurrentFloor.MainScript:9: invalid argument #2 to ‘random’ (interval is empty)
Line 9 -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Devfourms and other code
Code:
task.wait(0.5)
local playerTable = game:GetService("Players"):GetPlayers()
local seatTable = script.Parent.Seats:GetChildren()
local randomPlayer1 = playerTable[math.random(1, #playerTable)] -- selecting our first random player
table.remove(playerTable, 1)
local randomPlayer2 = playerTable[math.random(1, #playerTable)] -- selecting our second random player
table.remove(playerTable, 2)
local randomPlayer3 = playerTable[math.random(1, #playerTable)] -- selecting our third random player
table.remove(playerTable, 3)
local Seat1 = seatTable[math.random(1, #seatTable)] -- selecting our first random seat
table.remove(seatTable, 1)
local Seat2 = seatTable[math.random(1, #seatTable)] -- selecting our second random seat
table.remove(seatTable, 2)
local Seat3 = seatTable[math.random(1, #seatTable)] -- selecting our third random seat
table.remove(seatTable, 3)
if randomPlayer1 and randomPlayer2 and randomPlayer3 and Seat1 and Seat2 and Seat3 then
local c1 = randomPlayer1.Character
local c2 = randomPlayer2.Character
local c3 = randomPlayer3.Character
local hum1 = c1.Humanoid
local hum2 = c2.Humanoid
local hum3 = c3.Humanoid
-- SEAT 1 --
if Seat1:GetAttribute("occupied") == false then
c1:PivotTo(Seat1.CFrame)
task.wait(0.5)
Seat1:Sit(hum1)
if Seat1.Occupant then
Seat1:SetAttribute("occupied", true)
Seat1:SetAttribute("playerName", Seat1.Occupant.Parent.Name)
end
end
-- SEAT 2 --
if Seat2:GetAttribute("occupied") == false then
c1:PivotTo(Seat2.CFrame)
task.wait(0.5)
Seat2:Sit(hum2)
if Seat2.Occupant then
Seat2:SetAttribute("occupied", true)
Seat2:SetAttribute("playerName", Seat2.Occupant.Parent.Name)
end
table.remove(seatTable, 2)
table.remove(playerTable, 2)
end
-- SEAT 3 --
if Seat3:GetAttribute("occupied") == false then
c1:PivotTo(Seat3.CFrame)
task.wait(0.5)
Seat3:Sit(hum3)
if Seat3.Occupant then
Seat3:SetAttribute("occupied", true)
Seat3:SetAttribute("playerName", Seat3.Occupant.Parent.Name)
end
table.remove(seatTable, 3)
table.remove(playerTable, 3)
end
end
Yes the code is messy. tryna get it working before its improved.