How to fix random user id?

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)

image
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)
1 Like

dont use tonumber for something like this

and if u want a only number textbox just use
if not script.Parent.Text:match("%d+$") then
return
end

this might confuse you, its about string patterns you should really learn them they’re pretty useful

1 Like

Remote event is not firing now ;D, pls tell why

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)
        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)

can you give me the error, im no5 sure why

1 Like

What number did it print?I mean tell us

1 Like

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

Do not use to number, use the code i gave you earlier

put it behind the code and remove the tonumber

2 Likes

But it prints first line, and not last line

1 Like

It printed random user id first, now remote event totally does not work

1 Like

its now the issue of the remoteevent, im not really experienced at them but im sure its something breaking the code

1 Like

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.

path_to_textbox:GetPropertyChangedSignal("Text"):Connect(function ()
    path_to_textbox.Text = path_to_textbox.Text:gsub("%D+", "")
end)

It will need server-side validation.

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.

3 Likes

No error is printed, I tried to use pcall function to, none worked, any thing to fix in script?

its something with the remoteevent then

1 Like

I see man.try using
FireServer:(game.Players:GetUserIdFromNameAsync(script.Parent.TextBox.Text),script.Parent.MoneyValueBox.Text)

1 Like

That’s what I did first, later I changed it to variables, to find any errors in script

Now turns out the entire script broke ;D

he wants to detect numbers so that the intvalue will not break

1 Like

i have an idea, try to do the thing u did eariler then add this

if script.Parent.Textbox.Text:match("%d+$") then
–ur code
end

1 Like

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?

maybe its something with the textbox

1 Like