Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my Teleporter Script not workign why is it not woring?

Asked by 4 years ago

Teleport script not working

local tpos = game.Workspace.TP2.Position




local function touched(hit)
    local humanoid = hit.Parent:findFirstChild("HumanoidRootPart")
    if (humanoid ~= nil) then
    humanoid.CFrame = CFrame.new(Vector3.new(tpos))
end
script.Parent.Touched:Connect(touched)
end

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

(Scroll down for the answer or reading patiently for explains)

Uhm... Don't need to press enter too much, or your enter was broked :P

Ye, error occurred from line 6.

local function touched(hit)

I don't support you to do local function, but it's okay :P

Change the touched's bracket, touched(hit), become touched(function(hit).

This is because 'hit' is a type of neutral function (I don't know are this right) so you need to put function inside the bracket.

Ye, the neutral function will make its end become 'end)'. :P

Correct line 6:

function touched(function(hit)

Correct line 10:

end)

Line 7 also get problems, you should put :FindFirstChild() instead of :findFirstChild (Maybe it's the same I don't know :P )

I think change line 7 to this:

if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

Ye, that has an if statement. Line 9 below has a new end now :P

And also delete line 8, because it makes problems.

Correct entire script :

local tpos = game.Workspace.TP2.Position

function touched(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
    hit.Parent.Humanoid.CFrame = CFrame.new(Vector3.new(tpos)
   end
end)

script.Parent.Touched:Connect(touched)

Tpos xD I took its T-Pose

Hope I helped and bye :D

Secret : Lalala count how much ':P' here

Ad

Answer this question