When a player touch a part all players are teleported to another part

Hello can someone help me with that ? I dont know how can i make a script that when a player touch a part all players are teleported to another part . Could someone can help me please ?? For the moment i only have this script

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
– add the teleportation for all users

end

end)

1 Like

you would use a for loop:

for _,p in pairs(game.Players:GetPlayers()) do
   if p.Character then -- If the Player has a Character
      p.Character:MoveTo("Your Position Here") -- Teleports Player
   end
end

What this will do is Iterate through every Player (go through every Player) and check if they have a Character, if they don’t, this code will error since the don’t, thats why the if statement checks if the Player does have a Character, If the Requirement is met, it will teleport the Player

2 Likes
local Players = game:GetService("Players")
local AnotherPart = ANOTHERPARTHERE

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild(“Humanoid”) then
		for i,v in pairs(Player:GetPlayers()) do
			local char = v.Character
			if char then
				char.HumanoidRootPart.CFrame = AnotherPart.CFrame
			end
		end
	end
end)
1 Like

well that’s kind of rude

What is rude? charcharcharcharchar

Gave the Solution, Another person did the same thing and got the solution

1 Like

How? I just said i was rude that i did something, and someone just did the same thing and that was taken.

Its kinda sad to have that happen where you do something, and someone gets more when they did the same thing.

Nope, That would be a waste of my time.
I would have never gotten 200+ Solutions if thats what I was doing.

People try to get Solutions, Who cares if people like me, that’s not important, I know there are people who do just want Solutions and Likes, but dont Assume that about me

Neither do I

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.