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

Click Teleport teleports all players?

Asked by 7 years ago

I've found a teleportation script and I'm having trouble on editing it. I'm not too familiar with scripting but I can read it, but this one has been a problem for me.

This script is supposed to teleport you on click (with click detector), not anyone else. It works fine, but not how I want it to.

I want this script to teleport yourself when you click it, this script teleports everyone to that part when someone clicks it, any help? Thanks!

Script and more details below...

Script for the first part (named Teleport1)

function onClicked()

local c = game.Players:GetChildren() 
for i = 1, #c do 
c[i].Character.Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport2.Position)
end 

end 

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

Script for the second part (named Teleport2)

function onClicked()

local c = game.Players:GetChildren() 
for i = 1, #c do 
c[i].Character.Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport1.Position)
end 

end 

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

1 answer

Log in to vote
0
Answered by
65225 80
7 years ago
Edited 7 years ago
function onClicked()

local c = game.Players.LocalPlayer
c.Character.Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport2.Position)
end  

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

Use LocalPlayer this will return the player that had anything to do with the called function. In result, the player whom clicked the part will be teleported to the position of Teleport2.

Ad

Answer this question