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

How to teleport players who are touching a certain brick?

Right now i have a script that teleports all players when one person touches a button. I would like that when someone touches the button it teleports all players who are touching a transparent cannot collide brick. Please can someone give me a lot of help not just like little clues as i am fairly new to scripting. Here is the snippet of my code that teleports everyone

	local target = CFrame.new(19.756, 82.351, 18.742) --could be near a brick or in a new area
for i, player in ipairs(game.Players:GetChildren()) do
   --Make sure the character exists and its HumanoidRootPart exists
   if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
       --add an offset of 5 for each character
      player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)

				 end
end

2 answers

properly indent your code it makes it much easier to read

There are many ways to achieve:

like picking a position and then looping over players and compare the position if its Magnitude is below a distance then its in range

or this which is basically what u said:

local target = CFrame.new(19.756, 82.351, 18.742) --could be near a brick or in a new area

local part = workspace.thisCouldBeAnything -- canCollide needs te be turned off

local function GetTouchingParts(part)
   local connection = part.Touched:Connect(function() end)
   local results = part:GetTouchingParts()
   connection:Disconnect()
   return results
end

for _, touching in pairs(GetTouchingParts(part)) do
	if touching and touching.Parent:FindFirstChild("HumanoidRootPart") then
		touching.Parent.HumanoidRootPart.CFrame = target
	end
end

you could also use findpartsinRegion3 which is more reliable but more complex

Hello, so I remember I did like the same thing so I know the answer.

there's a script I did

local teleport = script.Parent

teleport.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Head.CFrame = CFrame.new(and here you need to type ur cords) end end)

That's the easiest way.

Hope I helped

1 comment

0

he wants only to teleport the ppl inside a part when a presses a button, not make a part keep on teleporting ppl after he presses a button

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