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

How would you make an OnTouch teleport to brick (part)?

Asked by
steev 0
10 years ago

The player walks on to a brick(part) and then gets teleported to another brick (part).

How would this work in Lua?

1 answer

Log in to vote
1
Answered by
nate890 495 Moderation Voter
10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
local part = script.Parent -- put script in part that teleports the player when touched otherwise edit
local teleportTo = game.Workspace.TELEPORTPART -- edit this line. part where player is teleported to

part.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        player.Character:MoveTo(teleportTo.Position)
    end
end)
0
If he wants an explanation then he can ask and I'll happily answer his questions. The code is pretty straight forward so I'm not going to waste my time to sugar coat it (especially after he "accepted" my answer.. nate890 495 — 10y
0
You should not use debounce in this code snippet. It will have a negative side affect if multiple players step on the brick at once. There is no need for it here. You should remove it from your code. -- I have edited your post to remove the debounce. User#11893 186 — 10y
0
You're kiding, right? nate890 495 — 10y
0
No, I am correct- you should not us debounce in this situation. User#11893 186 — 10y
View all comments (5 more)
0
There was never a debounce. nate890 495 — 10y
0
There was, I removed it from your post. User#11893 186 — 10y
0
You're my hero. You don't get a cookie though. nate890 495 — 10y
0
Just because the asker has marked the answer as acceptable, even without an explanation, that doesn't mean that anyone else who views the question will understand what is happening. User#2 0 — 10y
0
Then they could ask or find out for themselves. I'm not going to explain how to insert a BasePart and a script into the explorer, that would be redundant. nate890 495 — 10y
Ad

Answer this question