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

How to teleport a player, when he click a part?

Asked by 5 years ago
script.parent.GL.Touched:Connect(function(h)
    local hum = h.Parent:FindFirstChild("Humanoid")
    if hum ~= nil then
        h.parent.HumanoidRootPart.CFrame = CFrame.new(workspace["TelElTo"].Position)
    end
end)

script.parent.GR.Touched:Connect(function(h)
    local hum = h.Parent:FindFirstChild("Humanoid")
    if hum ~= nil then
        h.parent.HumanoidRootPart.CFrame = CFrame.new(workspace["TelElTo"].Position)
    end
end)

What i have to change in the script, when a player CLICKED and not touched the part that he will be teleported?

2 answers

Log in to vote
1
Answered by 5 years ago

You would have to add a "ClickDetector" inside your part. Then you need to add a local script into PlayerStarter --> StarterPlayerScripts.

Here is an example:

My part inside the Workspace

Workspace -- > gameT (part) --> ClickDetector

My local script:

function clicked()
    print("Hello!")
end

game.Workspace.gameT.ClickDetector.MouseClick:Connect(clicked)
Ad
Log in to vote
0
Answered by
pwx 1581 Moderation Voter
5 years ago

You'd have to use a ClickDetector instance. ClickDetector are used to allow Models/Parts to be clicked and fire an event upon being clicked (if the script is connected to it).

ServerScript

function OnMouseClick(Player) -- Keep in mind, player is always fired over as an argument
    print('The Player who clicked this is: '..Player.Name)
end

local Part = script.Parent

local ClickDetector = Instance.new('ClickDetector')
ClickDetector.Parent = Part

ClickDetector.MouseClick:Connect(OnMouseClick)

Put this code in a ServerScript and put the script inside a part you want to be clicked.

0
You can learn more about ClickDetectors here: https://developer.roblox.com/en-us/api-reference/class/ClickDetector pwx 1581 — 5y

Answer this question