Script isn't teleporting me!

Good afternoon!

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)

image

Please help!

You used Brick.Position

You’re setting CFrame so use Brick.CFrame

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.

Edit: I was wrong

Have you tried this script?

I think it’s gonna work

The part is deleted every single time the game boots up. This is so weird.

Have you used any toolbox stuff or someone else’s scripts?

Nope, only free model i’ve used in the game is a chair mesh. No scripts.

Is something unique going on the output?

I don’t think so. I’ve made half of the scripts by myself and used tutorials for the other half. But yet again, my part shouldn’t delete itself.

Try to remove Brick from your game, run it and show the output

Edit: If anything works on the Brick, an error should appear on the output after removing it

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?

1 Like

is the part anchored ? it could be falling down and getting deleted.

1 Like

What is this?

I have not come across these methods before

1 Like

You and ChouibeGamer fixed the issue. The part wasn’t anchored and the script was also unreliable. I wish I could put both of your posts as solutions.

1 Like

you should put the post that fixed your main question (not teleporting) as solution

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.

2 Likes