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

How to fix click detection with game teleporter?

Asked by 4 years ago

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

0
Code please Ziffixture 6913 — 4y
0
script.Parent.MouseButton1Click:connect(function() game:GetService("TeleportService"):Teleport(4880476521) end) funymemez 0 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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!

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? funymemez 0 — 4y
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. Ziffixture 6913 — 4y
Ad

Answer this question