Invalid member error

Hello,
I was coding an elevator and when pressing the button to use the elevator, the following error occured: "TeleportPart is not a valid member of Model “Workspace.Elevator.Capsule2”. Checking explorer, I don’t see how this is the case, as TeleportPart is part of Capsule2, which is part of Elevator, which is part of Workspace.
Here is the script:
local ElevatorFolder = game.Workspace.Elevator
local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
local SelectedCapsule = ElevatorFolder[“Capsule” … script.Parent.Name]
local TeleportPart = SelectedCapsule.TeleportPart

local Character = PlayerWhoClicked.Character
Character:SetPrimaryPartCFrame(TeleportPart)

end)

Try adding WaitForChild() calls to allow for instances to replicate before they are referenced from within the script.

Alright, I’ll try that and see if it works.

You might referenced the part wrong or the part got destroyed while the script is being made
try to see if the part is anchored as it might fallen into the void

Change line 8 to

Character:SetPrimaryPartCFrame(TeleportPart.CFrame)