Teleport takes two arguments: the player, then the place Id you want to be teleported to. (Looks something like 200445)
It only works in game, not studio so test in game once you fix the error.
#edit: code
changed a bit about your code.
you were getting the gui from the startergui which is not the player's gui. it The player gets a copy of that gui in startergui and then it gets put into the player's playergui.
also if the user enters a placeid in the text it needs to be a number.
there's also the scenario where the text entered isn't a placeId. we have pcall to stop script from erroring if that's the case. pcall takes code inside of a function and stops the code from breaking if the code inside pcall errors.
local Players = game:GetService("Players")
function onTouched(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
local placeId = tonumber(player.PlayerGui.OpenCloseGUI.Frame.TextBox.Text)
if Player then
wait(1)
print("Teleporting...")
local success, err = pcall(function()
game:GetService("TeleportService"):Teleport(Player, placeId)
end)
if success then
print("succesfully teleported player")
else
error("[WE HAD AN ERROR WHILE TELEPORING]: ", err)
end
print("Value = "..script.Parent.Value.Value)
end
end
script.Parent.Touched:Connect(onTouched)
1 comment
pls respond