Part teleport script


BackScript - don’t works

local part = game.Workspace.Partius

     local function onModelTouched(part)

script.Parent.Position = script.Parent.Part1.Position

end

MoveScript - works

while true do

script.Parent.CFrame = script.Parent.CFrame+Vector3.new(-2,0,0)

wait()

end

How to fix BackScript?

You never connected the function onModelTouched

local part = game.Workspace.Partius

local function onModelTouched(HitPart)
    script.Parent.Position = script.Parent.Part1.Position
end

part.Touched:Connect(onModelTouched)

It isn’t works :frowning_face:

Are you getting any errors in the Output?

1 Like

no, i am not getting any errors

Try this:

print("Online")
local part = game.Workspace.Partius

local function onModelTouched(HitPart)
    print("Touched/Fired")
    script.Parent.Position = script.Parent.Part1.Position
end

part.Touched:Connect(onModelTouched)

don’t works but image

print("Online")
local part = game.Workspace.Partius

local function onModelTouched()
    print("Touched/Fired")
    script.Parent.Position = script.Parent.Part1.Position
end

part.Touched:Connect(function()
       onModelTouched()
end)

You didn’t mention HitPart in the function so I erased it

Part touch part but it isn’t works

What its touching the part is another part or a model? If so, use the function SetPrimaryPartCFrame(script.Parent.Part1.CFrame). Remember if that the model does not have a primary part, it must be set!

You could also use MoveTo(), but the first one is better

Set the CanTouch property to true for both of them.

@stevenfury91 onModelTouched is a function itself. No need to use it under another function. This is the correct usage.

part.Touched:Connect(onModelTouched)

And HitPart parameter is used to define the part that touched.

local part = game.Workspace.Partius
local connection -- just for a debounce

local function onModelTouched(part)
print('Old Position', script.Parent.Position)
script.Parent.Position = script.Parent.Part1.Position
print('New Position:', script.Parent.Position)

connection:Disconnect()
end

connection = script.Parent.Touched:Connect(onModelTouched)