how would i make it, so that i can type coordinates inside a gui, and then it’ll tp a part to those coordinates?
To achieve this functionality you would need a local script, a server script, and a remote event. Here are example scripts that can do what you want:
LocalScript
local player = game.Players.LocalPlayer
local gui = script.Parent
local teleportButton = gui.TeleportButton
local coordinatesTextBox = gui.CoordinatesTextBox
local teleportEvent = game.ReplicatedStorage:WaitForChild("TeleportEvent")
teleportButton.MouseButton1Click:Connect(function()
local inputCoordinates = coordinatesTextBox.Text
-- Split the input string into x, y, and z values
local x, y, z = inputCoordinates:match("([^,]+),%s*([^,]+),%s*([^,]+)")
-- Convert to numbers
x, y, z = tonumber(x), tonumber(y), tonumber(z)
if x and y and z then
teleportEvent:FireServer(x, y, z)
else
-- Handle invalid input
error("Invalid coordinates")
end
end)
ServerScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local teleportEvent = Instance.new("RemoteEvent")
teleportEvent.Name = "TeleportEvent"
teleportEvent.Parent = replicatedStorage
teleportEvent.OnServerEvent:Connect(function(player, x, y, z)
local partToTeleport = game.Workspace.Part -- Replace this with the part you want to teleport
if partToTeleport then
partToTeleport.Position = Vector3.new(x, y, z)
end
end)
The correct input for the textbox is the following: (x value, y value, z value)
An example is 0, 0, 0
…so would it look like this?
and also, i dont know if im doing anything right… because all it does is say “invalid coordinates”
Hello again! Sorry if I left you confused, let me show you how the coordinates are supposed to be entered:
For this to work, you need to have the remote event in replicatedstorage.
and also the server script should be in ServerScriptService
To clear up any confusion about the hierarchy, the text box and button can be wherever you want, it doesn’t have to be specific to what I set originally. All you have to do is set the variable for each to where you put it.
From what I saw by the image you sent, your variables would be like this:
local teleportButton = script.Parent.Frame.TeleportButton -- Change this to wherever your teleport button is
local coordinatesTextBox = script.Parent.Frame.CoordinatesTextBox -- Change this to where your text box is
-- Rest of the code...
omg thx so much, not only for the code but also for being patient with me, also it just suddenly worked for some reason?? sry for saying it didnt work, i just had to wait, might have been a bug with studio
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.