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

Why Does My Click Teleporter Teleport All Players?

Asked by 4 years ago

i am using a click teleporter in my game but when i test it it teleports all the players instead of the one who clicked on it and i don't know why.

Here is the script: function onClicked()

local c = game.Players:GetChildren() for i = 1, #c do c[i].Character.UpperTorso.CFrame = CFrame.new(script.Parent.Parent.Teleport22.Position)--change "teleport" to the name of the object you want to be teled to... end

end

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

Tell me what to do to fix this please. Thank you

3 answers

Log in to vote
0
Answered by
o_fex 146
4 years ago
Edited 4 years ago

Sorry I forgot to add something: It should work now

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    player.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.PartTP.Position) 
end)
0
that does not work. i put a script inside the part i am clicking on with that exact script but changed the partyouwanttoteleportto to my part and nothing happend. still does not work  ErraticThe_legend27 8 — 4y
0
Try now o_fex 146 — 4y
0
nope still nothing ErraticThe_legend27 8 — 4y
0
Alright, where is your part, script and everything else located o_fex 146 — 4y
View all comments (2 more)
0
the part you click on is located in workspace inside a model the part im tping to is in the same model as the part you click to tp. the script is inside the part you click to tp along with a click detector. ErraticThe_legend27 8 — 4y
0
wait im dumb i just needed to ungroup them ErraticThe_legend27 8 — 4y
Ad
Log in to vote
0
Answered by
vocful 6
4 years ago

I personally do not know how to fix it as I not a great developer, but I do see the error. The error is when you said for i = 1,#c do. This means for a player, for all players in the server, do. You are calling ALL players to teleport. I'd say change local c = game.Players:GetChildren() to local c = game.Players.LocalPlayer:GetChildren(). Also maybe remove ,#c from for i = 1,#c do.

0
i tried to do that but it did not work. it just mde the click tp not work ErraticThe_legend27 8 — 4y
Log in to vote
0
Answered by 4 years ago

You are most likely running a server script. You'll want to replace it with a local script.

0
i replaced it with a local script and still nothing ErraticThe_legend27 8 — 4y

Answer this question