Gui Button Teleporting issue

I have a gui where if you click a button it will teleport you to the desired location, but everytime I click the button it says this,
Players.YUGOTA12CARGARAGE.PlayerGui.MiniMap.ImageLabel.TextButton.LocalScript:6: attempt to index nil with ‘CFrame’" Everything else works except for the CFrame part idk why.

wait(1)
local part = game.Workspace.Environments.QT:FindFirstChild("MCave1")
local player = game.Players.LocalPlayer
local Hum = player.Character:FindFirstChild("HumanoidRootPart")
script.Parent.MouseButton1Click:Connect(function() 
	Hum.CFrame = part.CFrame*CFrame.new(0,0,-4)
end)

Change
Character:FindFirstChild
to
Character:WaitForChild

Clients load 1st before the server

You should use Vector3

Hum.CFrame = part.CFrame + Vector3.new(0,0,-4)

It didnt work this is what it says in the output. Players.YUGOTA12CARGARAGE.PlayerGui.MiniMap.ImageLabel.TextButton.LocalScript:6: attempt to index nil with ‘CFrame’

1 Like

I dont know if this matters either but it is a local script not a server script.

To be honest a way you could do it more efficiently is by defining the character by defining it as:

local player = game.Players.LocalPlayer
local Character = workspace[player.Name]
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

And as opposed of putting a wait at the top instead of using the function :FindFirstChild("") you could just use the method :WaitForChild("").

I didnt work unfortunately it says this in the output

  Players.YUGOTA12CARGARAGE.PlayerGui.MiniMap.ImageLabel.TextButton.LocalScript:7: attempt to index nil with 'CFrame' 

You can’t do arithmetic equations with two CFrames, you may however do a CFrame definition followed by a adjusted Vector using the Vector3.new instance.

Hum.CFrame = part.CFrame * Vector3.new(0,0-4)

Sorry I dont know if im doing this wrong so im going to put the error along with the full script.

local part = game.Workspace.Environments.QT:FindFirstChild("MCave1")
local player = game.Players.LocalPlayer
local Character = workspace[player.Name]
local Hum = Character:WaitForChild("HumanoidRootPart")
script.Parent.MouseButton1Click:Connect(function() 
	Hum.CFrame = part.CFrame * Vector3.new(0,0-4)
end)

Error: " Players.YUGOTA12CARGARAGE.PlayerGui.MiniMap.ImageLabel.TextButton.LocalScript:7: attempt to index nil with ‘CFrame’"

local part = game.Workspace.Environments.QT:FindFirstChild("MCave1")
local player = game.Players.LocalPlayer
local Character = player.Character
local Hum = Character:WaitForChild("HumanoidRootPart")
script.Parent.MouseButton1Click:Connect(function()
     Hum.CFrame = part.CFrame + Vector3.new(0,0,-4)
end)

you need to add a “+” to make it work

This might help to figure it out, the local script is in a screengui (in StarterGui) then a image label then a text button. Maybe because of the location of the script is why it doesnt work. All it says in the output is ```
Players.YUGOTA12CARGARAGE.PlayerGui.MiniMap.ImageLabel.TextButton.LocalScript:6: attempt to index nil with ‘CFrame’

local part = game.Workspace.Environments.QT:FindFirstChild("MCave1")

So the “MCave1” is a model or a part?

if its a model you need to change de variable to a part since the model does not have a CFrame

MCave1 is a part in a folder called qt, I still dont know what is going wrong.

local part = game.Workspace.Environments.QT:WaitForChild("MCave1")
local player = game.Players.LocalPlayer
local Character = player.Character
local Hum = Character:WaitForChild("HumanoidRootPart")

script.Parent.MouseButton1Click:Connect(function()
    Hum.CFrame = part.CFrame + Vector3.new(0,10,0)
end)

oh, I found the error, you need to add “:WaitForChild”
try using this code and tell me if it worked

Thanks for helping with that issue, but there is another problem now. It says infinite yield possible, and the part wont load into the workspace.

Can you show me the part in the explorer?

Very wierd, do you have any script that deletes the part?

I dont think so, but findfirstchild in the scripts before looks like it forced the MCave1 part to load in, but it didnt work either way so i dont know what the problem is.

is your part (MCave1) anchored?