Hey DevForum! So I was working on something and was trying to make it so that, when your press next, it won’t let you forward unless the textbox text is a number.
productFunctions[1178702631] = function(receipt, player)
player.PlayerGui.Music.SongRequest.Visible = true;
player.PlayerGui.Music.SongRequest.Next.MouseButton1Click:Connect(function()
local Box = player.PlayerGui.Music.SongRequest.TextBox.Text
print(tonumber(Box))
if tonumber(Box) then
player.PlayerGui.Music.SongRequest.Visible = false;
table.insert(Requests, player.PlayerGui.Music.SongRequest.TextBox.Text)
for _, values in pairs(Requests) do
print(values)
end
end
end)
return true;
end
When I print the tonumber(string) value, it prints nil, even if the textbox text are only made up of numbers. I tried doing more DevForum research, all of them doing basically the same method. Thanks.
Happening because you’re trying to check the TextBox from a server script. Always why it’s a bad idea to try controlling Guis from a server script. Writing to a TextBox is client-sided input therefore only the client sees the new text in the TextBox.
You need a RemoteEvent. When the product is purchased, fire a RemoteEvent telling the client to make the song request Gui visible. The client, upon clicking the request button, should send the text of the TextBox to the server via RemoteEvent. The server can then validate (or sanitise) what the client has given it before inputting it into the queue.
local productFunctions = {}
local Requests = {}
productFunctions[1178702631] = function(receipt, player)
player.PlayerGui.Music.SongRequest.Visible = true;
return true;
end
game.ReplicatedStorage.Events.SubmitRequest.OnServerEvent:Connect(function(Player, Text)
if tonumber(Text) then
table.insert(Requests, tonumber(Text))
game.ReplicatedStorage.Events.SubmitRequest:FireClient(Player)
end
for i, val in pairs(Requests) do
print(val)
end
end)
And is this giving you problems or…? You replied with new code but didn’t explain what’s happening lol. Can’t tell if you meant for this to be the solution or if it’s problematic. Context would be helpful.