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)
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.