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
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)
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
.
You are most likely running a server script. You'll want to replace it with a local script.