I was working on a script where I would be teleported if I touched the lava. However, even though the part that i’m being teleported to is in workspace (Brick), it says that it couldn’t find it in workspace?!?!? Here’s my code and an image of where it is in explorer:
script.Parent.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
if hum ~= nil then
h.parent.HumanoidRootPart.CFrame = CFrame.new(workspace["Brick"].Position)
end
end)
script.Parent.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
if hum ~= nil then
h.parent.HumanoidRootPart.CFrame = workspace.Brick.CFrame
end
end)
Brick.position was working for me when I first used this script on 2 seperate parts. I guess I needed to change it or the game would have a crossfire with both scripts? Also, I just realized that the part itself is being deleted.
You can fix this issue by using the new Pivot API’s.
script.Parent.Touched:Connect(function(BodyPart)
local Humanoid = BodyPart.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
Humanoid.Parent:PivotTo(workspace["Brick"]:GetPivot())
end
end)
And I also cleaned up deprecated stuff, making this more reliable.
Also, next time, can you provide errors that you get in the output console?
The Pivot API’s are the replacement of the legacy :SetPrimaryPartCFrame() and :GetPrimaryPartCFrame(), which basically have less issues. I would recommend changing :SetPrimaryPartCFrame() with :PivotTo()
and :GetPrimaryPartCFrame() with :GetPivot()
As those 2 old API’s will be deprecated very soon.