Keeps saying part isn't apart of Player when I'm changing the CFrame

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to eject the player from the vehicle when they press the spacebar. Because the vehicle has collisions I have to teleport them to another part. (the part being “GetOutRR”)

  2. What is the issue? Include screenshots / videos if possible!
    I am trying to teleport them to a different part. Below is the error I’m getting.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    This is a pretty specific issue that I had a hard time finding. This is my code so far

local mouse=game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local veh = script.Parent.Parent.Parent.Parent.Parent
mouse.KeyDown:connect(function(key)
	if key==" " then
		game.Workspace:FindFirstChild(player.Name):FindFirstChild("HumanoidRootPart").CFrame = veh.GetOutRR.CFrame
		end
	end

Does anyone know why it’s saying that the part is not a valid member of the player, even though I’m not trying to find the part inside the player? I’m very new to coding so it might be obvious. This is also my first time asking for coding assistance, so sorry if I didn’t give enough information.

Where is the script located?
What does the vehicle look like in explorer?

I suspect you just have a couple of the variables wrong.

Sorry for the late response.

This is the workspace. Highlighted is the script, and the “GetOutRR”

maybe try using:

local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

instead of:

game.Workspace:FindFirstChild(player.Name):FindFirstChild("HumanoidRootPart")

I tried this now but keep getting the same error.

The issue is that the local script is getting moved when the ScreenGUI gets moved. This means that while it initially is a descendant of the car, it becomes a descendant of the player instead. You’ll need to access the vehicle through a different way, that doesn’t rely on a bunch of script.Parent.Parent.Parents…

This worked after a bit of tinkering. Thanks for your help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.