Teleport script wont work

ok so I’ve been wanting to learn more scripting and I came across this code that I thought could be useful in my game a lot of people said it had worked but it hasn’t worked for me for some reason

local CurrentLocation = script.Parent
local Destination = game.Workspace.Part2
-- (Optional), You can create local variable for each part.

CurrentLocation.Touched:Connect(function(Touch)-- Touched function.

    if Touch.Parent:FindFirstChild("HumanoidRootPart") then
-- Checks if the touched part parent contains 'HumanoidRootPart'
-- and if it does then this line of code will run.
        Touch.Parent:FindFirstChild("HumanoidRootPart").CFrame = Destination.CFrame + Vector3.new(0,3,0)
-- This teleports the player to the destination.

    end

end

I then changed it to this basically the same thing but I changed the local destination

local CurrentLocation = script.Parent
local Destination = game.Workspace.Teleporters.easy1
-- (Optional), You can create local variable for each part.

CurrentLocation.Touched:Connect(function(Touch)-- Touched function.

	if Touch.Parent:FindFirstChild("HumanoidRootPart") then
		-- Checks if the touched part parent contains 'HumanoidRootPart'
		-- and if it does then this line of code will run.
		Touch.Parent:FindFirstChild("HumanoidRootPart").CFrame = Destination.CFrame + Vector3.new(0,3,0)
		-- This teleports the player to the destination.

	end

end

The error occurs at the “end, end” part which I don’t know how to fix

1 Like

I have made altered your current script slightly and this should work:

local ThisPart = script.Parent
local Destination = workspace.DestinationPart

ThisPart.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

    if Player and Hit.Parent:FindFirstChild("HumanoidRootPart") then
        Hit.Parent.HumanoidRootPart.CFrame = Destination.CFrame + Vector3.new(0, 3, 0)
    end
end)
2 Likes

Yes thank you this did solve it

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.