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

I don't think this working correctly. can u help me?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Player = game.Players.LocalPlayer Cave1 = script.Parent Cave = game.Workspace.CaveTP HasPressedCave1 = false

function TeleportPlayer() if HasPressedCave1== false then Player.Character(MoveTo(Cave.Position))

    end
end

end

Teleport.MouseButton1Down:connect(TeleportPlayer)

k so im trying to make it where if i click on something with a click detector in it then it will teleport the player... i have been trying for about 2 days now but i cant figure it out. its not teleporting me though

1
Fix your codeblock please, then I can help. SlickPwner 534 — 10y
0
Also what is CaveTP HasPressedCave1? YasuYoshida 171 — 10y

2 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Well, you really need to put your code in a code block (that little blue Lua symbol) and tab it correctly.

Player = game.Players.LocalPlayer 
Cave1 = script.Parent
Cave = game.Workspace.CaveTP 
HasPressedCave1 = false

function TeleportPlayer() 
    if HasPressedCave1== false then 
        Player.Character(MoveTo(Cave.Position))
    end
end
end

Teleport.MouseButton1Down:connect(TeleportPlayer)

There's five problems that will prevent your code from running. First, the Teleport variable you use in the connection line is nil. You never create it.

Second, you have two many ends. You only need two; one to close the function, one to close the if statement.

Third, you're using MoveTo() wrong. Since MoveTo() is a method or function of a model, we must call it on that model. To do that, we use a colon, or :. Then, in the following parentheses, we must give it a Vector3 to move the model to.

Fourth, the MouseButton1Down event is used for GUIs, but ClickDetectors use the MouseClick event.

Fifth, your LocalPlayer variable makes it look like this is in a LocalScript, but LocalScripts only run inside a character, PlayerGui, or Backpack. Therefore, we must use a server script. Getting the player will not be a problem, however, because MouseClick events have a built in parameter equal to the player who clicked it.

Place this script inside the ClickDetector and see how it works.

local clickDetector = script.Parent
local teleportBrick = workspace:WaitForChild("CaveTP") --Use the WaitForChild() method in case CaveTP doesn't exist when we create the variable, due to lag.

script.Parent.MouseClick:connect(function(plr)
    if plr.Character then
        plr.Character:MoveTo(teleportBrick.Position)
    end
end)
Ad
Log in to vote
-1
Answered by 10 years ago

thank u much... but... u had an error in ur script...

in line 2 u said to reffer to CaveTP as teleportBlock

but in line 6 u called it teleportBrick

i fixed it though so thanks

0
Sorry about that. In the future, just leave a comment on my post though. Perci1 4988 — 10y

Answer this question