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

How to make a player teleport to a location by touching a brick? (answered)

Asked by 5 years ago
Edited 5 years ago

My Current Code:

01function onTouched(hit)
02 
03 
04--code to teleport players to a specific location
05if Teleport = true do
06    player.Character:MoveTo(Vector3.new(0,200,0))
07end
08 
09 
10end
11 
12script.Parent.Touched:connect(onTouched)

this script is parented to a brick, so what i'm trying to do is make a teleport brick that when the variable teleport is true, people can teleport to the main game and play, but I keep getting errors in all my attempts, also is there a way you can share variables across scripts for setting Teleport to true when the round has ended? Thanks

also teleport your player, not all players

Answered by Internal_1 :

1script.Parent.Touched:Connect(function(p)
2    player = game.Players:GetPlayerFromCharacter(p.Parent)
3    if player and Teleport then
4        player.Character:MoveTo(Vector3.new(0,200,0))
5    end
6end)
0
wut is the error saying KNOSIS 8 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
1script.Parent.Touched:Connect(function(p)
2    player = game.Players:GetPlayerFromCharacter(p.Parent)
3    if player and Teleport then
4        player.Character:MoveTo(Vector3.new(0,200,0))
5    end
6end)

Your two problems were that you were using one "=" for comparing, when you should use two, and the "do" at the end of the if statement should be "then" The reason why I changed :connect() to :Connect() is because :connect() is now deprecated. They both do the exact same thing, though. For your second question,

yes, it is possible to share variables across other scripts. The easiest way would be to use _G (the global table), though the cleanest would be to use a bindableFunction.

0
Error : "Workspace.Part.Script:2: attempt to index global 'Players' (a nil value)" Jack_Hase 85 — 5y
0
shoot xD fixed. I forgot the "game." somehow. Internal_1 344 — 5y
0
thank you!! Jack_Hase 85 — 5y
0
how do you mark this question as answered Jack_Hase 85 — 5y
Ad

Answer this question