I have a code that detects the empty seats and teleports the user to one of those seats when they join the game. At least that is what it is supposed to do when I test the game I have no errors or prints on my output. However, my player gets teleported with an offset of 36, 0, 4 and does not get the sitting animation. While this is mentioned, on the server side I am actually sitting on a seat which I can be sure of with the added “SeatWeld” as a child of the seat. Here is the part of the script responsible for teleporting the player.
UPDATE: I get the sitting animation now, I guess there was a problem with connection or something ._.
-- Function to automatically seat a player on an empty seat
local function autoSeatPlayer(player)
player.CharacterAdded:Connect(function()
for _, seatsModel in ipairs(seatsModels) do
local seat = findUnoccupiedSeat(seatsModel)
if seat then
-- Check if the player's character exists
local character = player.Character
if character then
-- Teleport the player to the unoccupied seat
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
humanoidRootPart.CFrame = seat.CFrame
-- Mark the seat as occupied using a SeatWeld
local seatWeld = Instance.new("Weld")
seatWeld.Name = "SeatWeld"
seatWeld.Part0 = seat
seatWeld.Part1 = humanoidRootPart
seatWeld.C0 = CFrame.new(seat.Position) -- Use CFrame.new to create a CoordinateFrame from the position
seatWeld.Parent = seat
else
print("Player's character does not exist. Unable to seat the player.")
end
break -- Break out of the loop after seating the player on the first available seat
else
-- Handle the case where no unoccupied seat is found in the current SeatsModel
print("No unoccupied seat found in this SeatsModel.")
-- You may want to handle this scenario based on your game's requirements.
end
end
end)
end