Hello, I am trying this function to teleport you if you have done the tutorial but it keeps saying, ServerScriptService.Tutorial.SetGuide:16: attempt to index nil with 'CFrame ;any help?
local function didTutorial()
local character = players.Character
local LowerTorso = character:WaitForChild("HumanoidRootPart")
if players.MapWorld.Value ~= 0 then
local MapArea = game.Workspace.Maps:FindFirstChild(players.MapWorld.Value)
LowerTorso.CFrame = MapArea.CFrame
end
end
It seems like either LowerTorso or MapArea are nil since that’s where .CFrame is being used. Try adding print(LowerTorso, MapArea) before the CFrame’s set to see which one’s nil.
if players.MapWorld.Value ~= 0 then
local MapArea = game.Workspace.Maps:FindFirstChild(players.MapWorld.Value)
print(LowerTorso, MapArea)
LowerTorso.CFrame = MapArea.CFrame
end
If LowerTorso isn’t nil, then HumanoidRootPart will be printed.
If MapArea isn’t nil, then the name of the map area will be printed.
Finding out which one is nil will let you know where the problem lies (either in the HumanoidRootPart or the map area not being retrieved).
Edit: the print(...) should be afterMapArea is defined.
If LowerTorso was nil it would have a yielding error trying to WaitForChild() it. Looks to me that it’s MapArea.
This can be solved by making sure MapArea exists before referencing it:
local function didTutorial()
local character = players.Character
local LowerTorso = character:WaitForChild("HumanoidRootPart")
if players.MapWorld.Value ~= 0 then
local MapArea = game.Workspace.Maps:FindFirstChild(players.MapWorld.Value)
if MapArea then
LowerTorso.CFrame = MapArea.CFrame
else
print("MapArea doesn't exist!")
end
end
end