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

How do I make it so that any brick named One will teleport to Two?

Asked by 7 years ago

Basically what it says up there . This script works and all but I can only click on one brick named One but not the others also named One.

local clickDetector=workspace["One"]["ClickDetector"]
local function onMouseClick(player)
  workspace.One.Position=workspace.Two.Position
  wait(1) 
  workspace.One["ClickDetector"]:Destroy()
end
clickDetector.MouseClick:connect(onMouseClick)
0
it works thanks!! lce_bear 31 — 7y

1 answer

Log in to vote
0
Answered by
Etheroit 178
7 years ago

It's easy. Use loop. Here is corrected code.

for _, i in pairs(game.Workspace:GetChildren()) do
     if i.Name == "One" then
          if i:FindFirstChild("ClickDetector") then
               i.ClickDetector.MouseClick:connect(function()
                    if game.Workspace:FindFirstChild("Two") then
                         i.CFrame = game.Workspace.Two.CFrame
                         i.ClickDetector:Destroy()
                    end
               end)
          end
     end
end
Ad

Answer this question