Hello, could someone please help me fix this issue in my script?
What do you want to achieve? I want to create a script that gets the number value of a textbox and checks if it is a whole number.
What is the issue? The script is setting the ‘text’ variable to the original text (“Please enter a number value!”), and not its current text. However, when inspecting the TextBoxes, the text value is a number. Other text values (like ContentText) are either also equal to the text or empty (PlaceHolderText)
What solutions have you tried so far? I have tried looking at similar topics in Scripting Support, but most of them are questions surrounding textboxes with RemoteEvents or client-side events.
(The textboxes say ‘3’ and ‘4’, but the script thinks that they still say 'Type a number value!)
local servstorage = game.ServerStorage
local dupfolder = servstorage.DuplicationPartSpawnFolder
local expfolder = workspace.PartSpawnFolder
local button = workspace.PartSpawner.Activator
local sign = workspace.PartSpawnSign
local frame = sign.SurfaceGui.Frame
local xsizecontrol = frame.XSizeControl
local ysizecontrol = frame.YSizeControl
local db = false
function sizeCheck(minvalue, maxvalue, text)
print(text)
local textValue = tonumber(text)
print(textValue)
if textValue % 1 ~= 0 then
text = "Please enter a whole number!"
end
end
button.Touched:Connect(function(hit)
print("a")
print(xsizecontrol.Text)
sizeCheck(1, 5, xsizecontrol.Text)
sizeCheck(1, 5, ysizecontrol.Text)
if db == false then
db = true
end
end)
For this we can use the type() function to type check if it’s a number.
if textValue % 1 ~= 0 then"
→ if type(textValue) ~= "number" or textValue % 1 ~= 0 then
local servstorage = game.ServerStorage
local dupfolder = servstorage.DuplicationPartSpawnFolder
local expfolder = workspace.PartSpawnFolder
local button = workspace.PartSpawner.Activator
local sign = workspace.PartSpawnSign
local frame = sign.SurfaceGui.Frame
local xsizecontrol = frame.XSizeControl
local ysizecontrol = frame.YSizeControl
local db = false
function sizeCheck(minvalue, maxvalue, text)
print(text)
local textValue = tonumber(text)
print(textValue)
if type(textValue) ~= "number" or textValue % 1 ~= 0 then
text = "Please enter a whole number!"
end
end
button.Touched:Connect(function(hit)
print("a")
print(xsizecontrol.Text)
sizeCheck(1, 5, xsizecontrol.Text)
sizeCheck(1, 5, ysizecontrol.Text)
if db == false then
db = true
end
end)
Sry, I think I might have typed this post in a confusing way. I want this script to be able to get the values that the player typed into the textbox (3 and 4 in this example).
Did you change the text in Studio Play testing? Because the script is running on the server and if you change it on the client, the server sees the old text and doesn’t see the number changed, you have to use remote events to communicate to the server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes.RemoteEventName
local button = workspace.PartSpawner.Activator
local sign = workspace.PartSpawnSign
local frame = sign.SurfaceGui.Frame
local xsizecontrol = frame.XSizeControl
local ysizecontrol = frame.YSizeControl
local db = false
button.Touched:Connect(function(hit)
print("a")
print(xsizecontrol.Text)
remoteEvent:FireServer(xsizecontrol.Text, ysizecontrol.Text)
if db == false then
db = true
end
end)
Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.Remotes.RemoteEventName
remoteEvent.OnServerEvent:Connect(function(player: Player, xSize: number, ySize: number)
...
end)