Scripting Issue Again | Teleporting Player

I just want to say sorry for all the questions I am just having issues.

  • What are you attempting to achieve? - Teleporting R6 player into a vehicle from a part.

  • What is the issue? - I am trying to make it so that if you touch the part it teleports your character into one of those 7 seats and when the seats are full, the vehicle drives [I already have the driving system scripted]

  • What solutions have you tried so far? - I’ve tried the wiki.

Once again, I apologise for asking so many questions :pensive:

Thanks!

Would you be any chance have any code to show, so that we may see if the issue is from your code?

All characters has a HRP(HumanoidRootpart) set as PrimaryPart, which you can use :SetPrimaryPartCFrame(seat.CFrame * CFrame.new(0,4,0)).

Attempting Solution – which is already too much to ask for – untested


local vehicle -- the vehicle model
local hitToSeat -- part of the vehicle
local seatTable = {} do
    for i, v in next, vehicle:GetDescendants() do
        if v:IsA("Seat") or v:IsA("VehicleSeat") then
            table.insert(seatTable, v:IsA("VehicleSeat") and 1 or #seatTable, v)

            v:GetPropertyChangedSignal("Occupant"):Connect(function()
                if not v.Occupant then
                    table.insert(seatTable, v:IsA("VehicleSeat") and 1 or #seatTable, v)
                end
            end)
        end
    end
end

hitToSeat.Touched:Connect(function(touched)
    if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
        if #seatTable > 0 then
            touched.Parent:SetPrimaryPartCFrame(seatTable[1].CFrame * CFrame.new(0,4,0))
            table.remove(seatTable, 1)
        end
    end
end)

Report any odd errors, this was written raw and not in Studio.

Optional
Use the Seat:Sit(touched.Parent.Humanoid) instead, which then does not require any teleportation immediately.

The script would look like this:

local vehicle -- the vehicle model
local hitToSeat -- part of the vehicle
local seatTable = {} do
    for i, v in next, vehicle:GetDescendants() do
        if v:IsA("Seat") or v:IsA("VehicleSeat") then
            table.insert(seatTable, v:IsA("VehicleSeat") and 1 or #seatTable, v)

            v:GetPropertyChangedSignal("Occupant"):Connect(function()
                if not v.Occupant then
                    table.insert(seatTable, v:IsA("VehicleSeat") and 1 or #seatTable, v)
                end
            end)
        end
    end
end

hitToSeat.Touched:Connect(function(touched)
    if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
        if #seatTable > 0 then
            seatTable[1]:Sit(touched.Parent.Humanoid)
            table.remove(seatTable, 1)
        end
    end
end)

And finally, if it’s not driven by a player, ignore VehicleSeat and replace table.insert(seatTable, v:IsA("VehicleSeat") and 1 or #seatTable, v) with table.insert(seatTable, v).

Automatic driving or enabling it will require that the #seatTable <= 0 is true.

1 Like

Hello there, I used your script suggested

local Vehicle = game.Workspace.TestBoat1
local hitToSeat = game.Workspace.BoatJoiner1
local seatTable = {} do
	for i,v in next, Vehicle:GetDescendants() do
		if v:IsA("Seat") or v:IsA("VehicleSeat") then
			table.insert(seatTable, v:IsA("VehicleSeat") and 1 or #seatTable, v)
			
			v:GetPropertyChangedSignal("Occupant"):connect(function()
				if not v.Occupant then
					table.insert(seatTable, v)
				end
			end)
		end
	end
end

hitToSeat.Touched:Connect(function(touched)
	if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
		if #seatTable > 0 then
			touched.Parent:SetPrimaryPartCFrame(seatTable[1].CFrame * CFrame.new(0,4,0))
			table.remove(seatTable, 1)
		end
	end
end)

But when I stand on the platform it still doesn’t teleport my character into a seat.

Actually the PrimaryPart of some Humanoids is the Head.

That’s only when the HumanoidRootPart does not exist. It changes when one part is missing in some sort of priority. It starts from the HumanoidRootPart, moving to Head and then followed up by the Torso or similar and then other limbs.

This is intended as the PrimaryPart was supposed to be the camera focus by default. When it’s missing, camera moves to the next PrimaryPart.

If no body parts left, the camera is stuck mid-air.

@Hikoutai Try the other script that I’ve provided. It uses Seat:Sit() function from a Seat.

Excuse me? That’s happened in live games with Player characters.

And the camera focused on the head.

Not entirely sure how that happened. In what games, if you have, do you know that the HumanoidRootPart is missing?

Why not try this in Studio?

  • Spawn in, make sure spawn timer is high enough to test.
  • Remove HumanoidRootPart, check camera focus
  • Remove Head, check camera focus
  • Remove Torso or similar, check camera focus

The HumanoidRootPart is not missing or the player would be dead…

Not true.

This statement is false. According to the test I’ve made, the player does not die from the removal of HumanoidRootPart. Only when Head or Torso(or similar) removed will cause the character to die.

Addendum: A small correction to my own posts. Apparently, the camera DO focus the Head first. Followed up by other parts to avail in the character model.

I guess so. The HumanoidRootPart was obviously still present, I even had to make changes in my scripts to stop using PrimaryPart (the Head) and use HumanoidRootPart explicitly instead.

3 Likes