Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Does My Click Teleporter Teleport All Players?

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

✓ Accepted answer

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)

6 comments

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 

0

Try now

0

nope still nothing

0

Alright, where is your part, script and everything else located

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.

0

wait im dumb i just needed to ungroup them

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.

1 comment

0

i tried to do that but it did not work. it just mde the click tp not work

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

1 comment

0

i replaced it with a local script and still nothing

This discussion is preserved as it was. New answers, comments, and votes are closed.