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

Making a Clickable brick that teleports you to another game?

Hi, I'm currently working on a teleport button that teleports you to another game when you click it instead of stepping over it. I went off with the onTouch first, to see how it works and it does. But, when I try to make a click function of it, it doesn't work at all.

I put the click detector in a part, and then a script in the part. and the part is in workspace.


local TeleportService = game:GetService("TeleportService")
 
local placeID_1 = 4505065903
local placeID_2 = 4483453486

script.Parent.ClickDetector.MouseClick:Connect(function()
	local player = game.Players:GetPlayerFromCharacter(script.Player)
	if player then
		TeleportService:Teleport(placeID_1, player)
	end
end)

I didn't know exactly what to put in where it says "script.Player" so can I get help on that too?? Image here: https://gyazo.com/6865b0516ac27265ad2f02cf1bceada2

1 answer

✓ Accepted answer

ClickDetectors will always have a parameter of the player who clicked. So there is no need to use GetPlayerFromCharacter whatsoever.

local TeleportService = game:GetService("TeleportService")

local placeID_1 = 4505065903
local placeID_2 = 4483453486

script.Parent.ClickDetector.MouseClick:Connect(function(player)
        TeleportService:Teleport(placeID_1, player)
end)

3 comments

0

Oh, wow thank you!

0

Wait it still doesn't work

0

I fixed it, I also didn't need to clarify ClickDetector twice since the scripts parent is the ClickDetector

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