I made a script, in my game, which you can send your game money like paypal, the thing is when I enter my name, I get random userid each time
Local script:
script.Parent.TextButton.MouseButton1Click:Connect(function()
if script.Parent.TextButton.BackgroundTransparency == 0 and tonumber(script.Parent.MoneyValueBox.Text) ~= nil then
print(script.Parent.TextBox.Text) -- prints my name correctly
game.ReplicatedStorage.SendMoneyEvent:FireServer(tonumber(game.Players:GetUserIdFromNameAsync(script.Parent.TextBox.Text),script.Parent.MoneyValueBox.Text))
end
end)
You see, my name is printed,as in script I kept print function
But, when sending remote event, then it prints 9333129221
Idk whose userid is this, my userid is 399226415, but it printed some random number
-- Server Side script
game.ReplicatedStorage.SendMoneyEvent.OnServerEvent:Connect(function(plr,toplr,totalmoney)
print(toplr) -- it prints random number why
end)
script.Parent.TextButton.MouseButton1Click:Connect(function()
if script.Parent.TextButton.BackgroundTransparency == 0 and tonumber(script.Parent.MoneyValueBox.Text) ~= nil then
print(script.Parent.TextBox.Text)
local playertosend = game.Players:GetUserIdFromNameAsync(script.Parent.TextBox.Text)
game.ReplicatedStorage.SendMoneyEvent:FireServer(playertosend,script.Parent.MoneyValueBox.Text)
print("Sent") -- does not print
end
end)
It does not print any error, and the script I sent you just now, it prints first line, but does not print in last line, script stops working in between
FYI: I don’t want to hijack this thread to focus on a single solution, but if your goal is to reject any non-numeric inputs from the code and also assuming that you only need positive integers, then you can just apply masking strategies to coerce the text to only accept numeric inputs. Requires a changed event.
You don’t have to wholly reject the input if it’s non-numeric. That being said, the type of input seems irrelevant to the problem. There’s not any real context for the problem so it’s somewhat difficult to determine the source of error and why a “random number” comes back. You could construct a simple repro for this by having the client fire this pattern to the server and check what comes back.
Yes, also after removing this line tonumber(script.Parent.MoneyValueBox.Text) ~= nil local script worked and remote event was fired, but server side, it printed random userid again
Whats wrong with tonumber(script.Parent.MoneyValueBox.Text) ~= nil ,its a number and tonumber(text) is printing nil, its not a string why it prints nil?