Oh sorry i forgot to update the script i edited it after i noticed it was a little broken uhh maybe this should work if it doesnt im really confused on why
local Seats = {
game.Workspace.Couch1.Seat1,
game.Workspace.Couch1.Seat2,
}
local Players = game:GetService("Players")
function SeatOccupied(Seat)
local weld = Seat:FindFirstChild("SeatWeld")
if weld then
return weld
end
end
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
spawn(function()
local hrp = character:WaitForChild("HumanoidRootPart")
local AvailableSeats = {}
for _,v in pairs(Seats) do
if not SeatOccupied(v) then
table.insert(AvailableSeats,v)
end
end
local PickedSeat
if #AvailableSeats > 0 then
PickedSeat = AvailableSeats[math.random(1,#AvailableSeats)]
hrp.CFrame = PickedSeat.CFrame
else
PickedSeat = Seats[math.random(1,#Seats)]
hrp.CFrame = PickedSeat.CFrame * CFrame.new(0,SeatOccupied(PickedSeat).Part1.Size.Y + 1 + hrp.Size.Y,0)
end
end)
end)
end)
thanks so much it works and also if i was able to add more seats and stuff do i just add on to the
game.workspace.2ndcouchname.2ndseatname and it would still work
and sorry to ask to much but is there away to where i can make it like spawn me right away instead of me falling outside the place then spawning there. I dont want people in my game to see the outside of map
local Seats = {
workspace.TestSeat1,
workspace.TestSeat2,
workspace.TestSeat3,
-- and add some more if u want just dont forget the comma at the end of each of them
}
It would need a little modification but fortunately this one isnt hard to change for local script so here
local Seats = {
game.Workspace.Couch1.Seat1,
game.Workspace.Couch1.Seat2,
}
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
function SeatOccupied(Seat)
local occupant = Seat.Occupant
return occupant
end
function teleportToSeat()
local AvailableSeats = {}
for _,v in pairs(Seats) do
if not SeatOccupied(v) then
table.insert(AvailableSeats,v)
end
end
local PickedSeat
if #AvailableSeats > 0 then
PickedSeat = AvailableSeats[math.random(1,#AvailableSeats)]
hrp.CFrame = PickedSeat.CFrame
else
PickedSeat = Seats[math.random(1,#Seats)]
hrp.CFrame = PickedSeat.CFrame * CFrame.new(0,SeatOccupied(PickedSeat).Parent.PrimaryPart.Size.Y + 1 + hrp.Size.Y,0)
end
end
teleportToSeat()
btw put this inside a local script in StarterPlayer>StarterCharacterScripts
wdym by that. The code does work fine for me now but I just want to know bec maybe that will fix it from me still loading outside but only for like few seconds
oh its just when i said this earlier but im assuming you know how tables work. also idk why ur still outside for a little bit maybe just cuz ur character is loading