I have code that will teleport a player to a coordinate they set in a textbox. I used tonumber() on each of the textboxes but when I type a number into them and click the button, the output says "nil"
I know that if you type anything else but a number into a tonumber() function, it will return nil. I don't know why this is happening. I'm typing a number into a textbox.Text with tonumber() on it but it's still returning nil.
Does anyone know how to fix this issue? Thanks!
Code:
local player = game.Players.LocalPlayer
local playergui = player.PlayerGui
local character = player.Character
local XCoordText = tonumber(playergui.ScreenGui.X.Text)
local YCoordText = tonumber(playergui.ScreenGui.Y.Text)
local ZCoordText = tonumber(playergui.ScreenGui.Z.Text)
local Teleport = script.Parent
Teleport.MouseButton1Click:Connect(function()
if typeof(XCoordText) or typeof(YCoordText) or typeof(YCoordText) == nil then
print(typeof(XCoordText, YCoordText, ZCoordText))
script.Parent.Text = "Please type a correct value."
wait(2)
script.Parent.Text = "Button"
else
print(typeof(XCoordText, YCoordText, ZCoordText))
character:MoveTo(Vector3.new(XCoordText, YCoordText, ZCoordText))
end
end)

6 comments
what are xcoord,ycoord and zcoord when you print them?
also what are you trying to say with your if statement?
They say nil even when I type a number and my if statement is if the thing I type into them is nil print what type they are, else the type it is when it's you can teleport a player.
what is the text originally i mean
do print(":".. playergui.ScreenGui.X.Text..":")
It says this :123