Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

1

Fix your codeblock please, then I can help.

0

Also what is CaveTP HasPressedCave1?

2 answers

✓ Accepted answer

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)

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

1 comment

0

Sorry about that. In the future, just leave a comment on my post though.

This discussion is preserved as it was. New answers, comments, and votes are closed.