I'm trying to create a game teleporter that is activated by click detection but when I click on the button, nothing happens. (the button is a physical brick).
This is because you cannot use the .MouseButton1Click
signal on anything but a GUIButton
. To actively program a clickable Part, you’ll need to use an Object called a ClickDetector
. Ensure this Instance is a child of the Part. By placing a script within the ClickDetector
, you can use its activation signal .MouseClick
to attach a listener.
local TeleportService = game:GetService("TeleportService") local GamePlaceId = --// PlaceId local ClickDetector = script.Parent ClickDetector.MouseClick:Connect(function(PlayerClicked) TeleportService(GamePlaceId, PlayerClicked) end)
The ClickDetector
also requires a ServerScript
to operate properly, as this Instance can only be used with a physical environment; this environment is workspace
which is a global space, LocalScripts can only run in local environments
Since we’re using a ServerScript now, we have to supply the second argument to the :Teleport()
method as it no-longer recognizes the Client automatically. Fortunately, ClickDetectors
supply a parameter which contains the Player Object that initiated the detector.
If this helps, don’t forget to accept this answer!