Hello, I am very new to scripting. I've been watching AlvinBlox's YoutTube series on how to make a game as a starting point in my Lua Learning. The problem lies within trying to teleport players to a specific part on a cloned map. I'll include the teleport portion of the main script, and the video that I'm currently learning from. I've been comparing my script with AlvinBlox's, but I cannot find the solution.
The map is successfully cloned when I test it, but the problem lies within, character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
which leads to the teleport script not being able to function, the error being "attempt to index nil with CFrame"
Thanks in advance.
local SpawnPoint = ClonedMap:FindFirstChild("SpawnPoint")
if not SpawnPoint then
print("Spawnpoints not found")
end
local AvailableSpawnPoints = SpawnPoint:GetChildren()
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
-- Teleport
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
table.remove(AvailableSpawnPoints,1)
--Give sword
local Sword = ServerStorage.Sword:Clone()
Sword.Parent = player.Backpack
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
-- There is no character
if not player then
table.remove(plrs,i)
end
end
end
end

2 comments
Thanks for the solution, but I'm still presented with the same error with the CFrame. This is what I did: I added "or player.CharacterAdded:Wait()" and "wait()" to the already existing "character = player.Character" I already assumed that I had to define "HMP", so I wrote "local HMP = character:WaitForChild("HumanoidRootPart")" and followed it with the rest of the code you suggested.
I played around with the string value for HMP, adding such things as "Head" after WaitForChild, but got the same error.