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
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
Closed as Not Constructive by Leamir
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?