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

How to fix click detection with game teleporter?

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).

2 comments

0

Code please

0

script.Parent.MouseButton1Click:connect(function() game:GetService("TeleportService"):Teleport(4880476521) end)

1 answer

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!

2 comments

0

Sorry, but i'm new to roblox code and i'm a bit confused. Anyways, you mentioned a server script, and what code do I put in it?

0

The code above. Essentially, you cannot use the code you’re using because it’s only compatible with GUIs. To make a program use Click Detection on Parts, you need a ClickDetector, and a .MouseClick signal as opposed to .MouseButton1Click.

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