How to make it so when a specific model touches a part the model teleports to a another model

help pls but give me a little support because I bad at scripting

(this is what I want)
image

2 Likes

That is simple
Part1.Touched:Connect(function(hit)
If hit.Parent:IsA(“Model”) then
hit.Parent:SetPrimaryPartCFrame(part2.CFrame)
end
end)

1 Like

They are talking about a specific model, so instead:

Part1.Touched:Connect(function(hit)
  If hit.Parent == game.Workspace.part1 then
    hit.Parent:SetPrimaryPartCFrame(part2.CFrame)
   end
end)

probably a good idea to store part1 as a variable, but yea this should work

Part1.Touched:Connect(function(hit)
If hit.Parent:FindFirstChild(“beteleported”) then
hit.Parent:SetPrimaryPartCFrame(part2.CFrame)
end
end)

i think this should be better, it allows you to add more models to be teleported in an easy way

image
image
it isn’t working do you know what is going wrong? Am i supposed to put it in a specific place?

  1. You need to define Part1 as a variable.
  2. The if statement needs to start with a low case if, not If.
  3. Replace the ''beteleported'' with"beteleported".
  4. You need to define Part2 as a variable.

Uh so I don’t know really how to define a variable in Lua can you teach me how?..

local Part1 = ..path.to.Part.
local Part2 = ..path.to.Part.

Replace ..path.to.Part. with the location of those parts. Example:

local Part1 = workspace:FindFirstChild("Part1")

image


For some strange reason whenever I start playtest the script disapears…
image
am i doing something wrong?

yea u still didn’t change the If to an if : P

Oh yeah i forgot, but still the script is going poof any clue where it went?

I dont know where exactly server script services puts scripts to, but it isn’t a problem, the script should still run fine (if it doesn’t, did you indent the hit.Parent:SetPrimaryPart line?)

I did
image
oh wait ima try defining “beteleported”

Put this in the script 'beteleported' in line 5


Still noD:
image
image

replace line 5 with if hit.Parent == script.Parent

image
Like this?

Yes

instead of using :SetPrimaryPartCFrame() I recommend using :PivotTo() instead as it does the same thing but with better performance

So with your code it would look like:

local Part1 = workspace:WaitForChild("Part1")
local Part2 = workspace:WaitForChild("Part2")


Part1.Touched:Connect(function(hit)
	if hit.Name == "beteleported" then	
		-- no need to grab the parent since the part touching it is all we need
		hit:PivotTo(Part2.CFrame)
	end
end)
1 Like

bro you didn’t, indend like 6 : P

1 Like