Every time I try to get/print the TextBox.Text value in a LocalScript the output is always nil.
Numbers written on the TextBox are supposted to always go thru, only when the player doesn’t write anything or writes anything except a number the output is supposted to be nil.
Here is the LocalScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local inputEvent = ReplicatedStorage:FindFirstChild("Input")
local event = ReplicatedStorage:FindFirstChild("DoGuiTeleport")
local input = tonumber(game.Players.LocalPlayer.PlayerGui.Teleport.Frame.Specific.TextBox.Text)
local path = game.Players.LocalPlayer.PlayerGui.Teleport.Frame.Specific.Info.Destination
local stage = game.Players.LocalPlayer.leaderstats.Stage.Value
script.Parent.MouseButton1Down:Connect(function()
print(input)
if input ~= nil then
if input <= stage then
inputEvent:FireServer(path, input)
wait(0.5)
event:FireServer(path)
script.Parent.Parent.Parent.Visible = false
elseif input > stage then
script.Parent.Parent.TextBox.PlaceholderText = "You can only teleport to stages you've already completed!"
wait(1)
script.Parent.Parent.TextBox.PlaceholderText = "Specific Stage"
end
else
script.Parent.Parent.TextBox.PlaceholderText = "Input a valid stage!"
wait(1)
script.Parent.Parent.TextBox.PlaceholderText = "Specific Stage"
end
end)
You’re defining the input variable immediately at the top of the script, which means it is just going to return whatever is in the TextBox at the start rather than whatever is in it when you actually press the button.
This should work:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local inputEvent = ReplicatedStorage:FindFirstChild("Input")
local event = ReplicatedStorage:FindFirstChild("DoGuiTeleport")
local path = game.Players.LocalPlayer.PlayerGui.Teleport.Frame.Specific.Info.Destination
local stage = game.Players.LocalPlayer.leaderstats.Stage.Value
script.Parent.MouseButton1Down:Connect(function()
local input = tonumber(game.Players.LocalPlayer.PlayerGui.Teleport.Frame.Specific.TextBox.Text)
if input ~= nil then
if input <= stage then
inputEvent:FireServer(path, input)
wait(0.5)
event:FireServer(path)
script.Parent.Parent.Parent.Visible = false
elseif input > stage then
script.Parent.Parent.TextBox.PlaceholderText = "You can only teleport to stages you've already completed!"
wait(1)
script.Parent.Parent.TextBox.PlaceholderText = "Specific Stage"
end
else
script.Parent.Parent.TextBox.PlaceholderText = "Input a valid stage!"
wait(1)
script.Parent.Parent.TextBox.PlaceholderText = "Specific Stage"
end
end)