Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to teleport player via Textbox?

I am lost right now. So currently I am trying to make a GUI where It'll teleport the player to a specific part when the player enters a specific number. (e.g 1, 2, 3, 4)

How would I go about this?

local Textbox = script.Parent
local Player = game:GetService("Players").LocalPlayer
local Stage = game.Workspace:WaitForChild("Stages")
local HumanoidRootPart = Player:FindFirstChildOfClass("HumanoidRootPart")

Textbox.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		for i, stages in pairs(Stage:GetChildren()) do
			if stages:IsA("BasePart") then		
				local NumberText = tonumber(Textbox.Text)
				local StageNumber = tonumber(stages.Name)
				
				if NumberText == StageNumber then
					-- Teleport player or something
				end
			end
		end
	end
end)

2 comments

0

are you trying to find out how to teleprt them

0

Yes.

1 answer

✓ Accepted answer

If I understand correctly, you want the character to teleport to a certain stage they inputted on a textbox?

local Textbox = script.Parent
local Player = game:GetService("Players").LocalPlayer
local Stage = game.Workspace:WaitForChild("Stages")
local HumanoidRootPart = Player.HumanoidRootPart

Textbox.FocusLost:Connect(function(enterPressed)
    if enterPressed then
        for i, stage in pairs(Stage:GetChildren()) do
            if stage:IsA("BasePart") then      
                local NumberText = tonumber(Textbox.Text)
                local StageNumber = tonumber(stage.Name)

                if NumberText == StageNumber then
                    HumanoidRootPart.CFrame = CFrame.new(stage.Position) * CFrame.new(0,4,0) --Just so it does not get stuck in ground
                end
            end
        end
    end
end)

I just added the CFrame part which teleports the player to the stage.

1 comment

1

Modified your script a little and got it working, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.