Is it possible to make a script where a player could input a game ID and when the part is touched it would teleport them to the selected game. I have the teleportation script here. Any response is helpful!
local TeleportService = game:GetService(“TeleportService”)
local Place = IDNOTMADEYET
script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
What I need is a explanation/help/script where a player would type a game ID into a GUI and with that, the part would teleport you to that given ID when touched.
local Textbox = script.Parent -- Location of textbox
local DefaultId = "000000" -- Default id
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") -- Your remote event
local function format(t) -- Make sure text contains only numbers
return t:gsub("[^0-9.-]", "")
end
Textbox:GetPropertyChangedSignal("Text"):Connect(function()
Textbox.Text = format(script.Parent.Text)
if Textbox.Text ~= (nil or "") then
Textbox.Text = tonumber(Textbox.Text)
else
Textbox.Text = DefaultId
end
RemoteEvent:FireServer(tonumber(Textbox.Text))
end)
Do this in your Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local Part = script.Parent
local TeleportService = game:GetService("TeleportService")
local Place = 000000
RemoteEvent.OnServerEvent:Connect(function(Player, Id)
if Player and Id then
if Id ~= "" then
Place = tonumber(Id)
end
end
end)
Part.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player and Place then
TeleportService:Teleport(Place, Player)
end
end)
Let me know if it works! (Make sure to include RemoteEvent in ReplicatedStorage) Let me know if you have any questions about the code