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)
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’
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.
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)
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: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
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.