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:

function onTouched(hit)


--code to teleport players to a specific location
if Teleport = true do
    player.Character:MoveTo(Vector3.new(0,200,0))
end


end

script.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 :

script.Parent.Touched:Connect(function(p)
    player = game.Players:GetPlayerFromCharacter(p.Parent)
    if player and Teleport then
        player.Character:MoveTo(Vector3.new(0,200,0))
    end
end)
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
script.Parent.Touched:Connect(function(p)
    player = game.Players:GetPlayerFromCharacter(p.Parent)
    if player and Teleport then
        player.Character:MoveTo(Vector3.new(0,200,0))
    end
end)

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