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

How do I make a teleport brick?

Asked by 9 years ago

How do I make a brick that, when touched, will teleport players to a set of co-ordinates? All the other questions haven't helped. I want to know how to target the SPECIFIC PLAYER who touches the brick & how to teleport him/her...

3 answers

Log in to vote
0
Answered by 9 years ago

Learn about functions and cframing.

Ad
Log in to vote
-1
Answered by 9 years ago

Like this.

coordinates = Vector3.new(0,0,0) --Vector3 of the location

script.Parent.Touched:connect(function(h)
    if game.Players:GetPlayerFromCharacter(h.Parent) then --make sure it's a player
        h.Parent:MoveTo(coordinates)
    end
end)

So, I'll explain this. First off, we need to use the Touched event. This fires whenever a brick is touched, and can be used like this:

game.Workspace.Brick.Touched

Obviously that won't do anything so we have to connect it to a function.

game.Workspace.Touched:connect(nameOfFunction)

Anyways, I'm sure you know how to do that, and I like to make my functions in the arguments, but further on;

We can check if the parts parent, which should be a limb of a player, is indeed a player using the GetPlayerFromCharacter method. You can learn more about that here.

And lastly, since we checked if it indeed is a player who touched the brick, we can 'teleport' them using the MoveTo method. This method can be used to make a person walk if the argument is a humanoid, but if we use it on a character it will teleport them to the desired Vector3. We can use this method like this:

Character:MoveTo(game.Workspace.Part.Position) --Position is a Vector3 so you can use it.

I hope I explained well enough, have a great time making your game!

0
I recommend you read the guidelines on https://scriptinghelpers.org/help/how-post-good-questions-answers. This answer doesn't explain the code, it just gives code. I'll give my own answer once this time limit is up. TheLuaWeaver 301 — 9y
0
Good enough edit? systematicaddict 295 — 9y
Log in to vote
-1
Answered by 9 years ago

To move a brick, you must change the CFrame. This sets the location and rotation of the part. To move a character, you have to move the "Torso" part to somewhere else. Thus, setting the character's torso's CFrame somewhere else will teleport them!

To do this, first, listen to the "Touched" event of the part. brick.Touched:connect(function(hit)

Then, check if "Torso" exists. This is to make sure it's a valid player or AI/other humanoid.

if hit.Parent:FindFirstChild("Torso") then

Finally, move the torso.

hit.Parent.Torso.CFrame=CFrame.new(0,0,0) -- moves to location (0,0,0); change to where you want

Then add the ends.

end end)

Finally, the whole script:

brick.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Torso") then
        hit.Parent.Torso.CFrame=CFrame.new(0,0,0)
    end
end

Answer this question