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

How to teleport player on click (RobloxStudio)?

Asked by 6 years ago

This is the code that isn't working for me.

I just want to move character away from that room that he is in after clicking. I give money when player clicks so i don't want them to keep clicking so any solution would be good. even if player goes back to spawn

function onClicked()
local p = game.Players:GetChildren()
for i = 1, #p do
p[i].Character:MoveTo(Vector3.new(0, 500, 0))
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Aprishiate all help

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago
Edited 6 years ago

The code you have now would teleport every player. To teleport you, the MouseClick event returns the player who clicked - so you can use the MoveTo function on the Character Property of the parameter returned.

**Note: connect is deprecated. Use Connect!
local location = Vector3.new(0,500,0) --Change this to where you want to go to.

function onClicked(p) --'p' parameter is who clicked
    local char = p.Character --get their character and move it
    char:MoveTo(location)
end

--'Connect' instead of 'connect'
script.Parent.ClickDetector.MouseClick:Connect(onClicked)
Ad

Answer this question