Can someone help me fix this data issue with text boxes

hello there I’m trying to take user input to set ranks
image
custom rank is the button and 1111 is the rank for it to set
in the code bellow
script.Parent.rankdata.Text
is the user input 1111
whenever I click on it sets the rank to nil

local Remote = script.Parent.RemoteEvent

Remote.OnServerEvent:Connect(function(plr)
 local main = _G.HDAdminMain
main:GetModule("cf"):SetRank(game:GetService("Players")[plr.name], game.CreatorId, script.Parent.rankdata.Text, "Perm")  
end)

Because the TextBox text is being set on the client, you will need to pass the text through a remote as trying to get a client change on the server will return false results.

1 Like

can you give me sample code im new to remotes

1 Like

When firing the remote, just add an argument that gets the TextBox text. Then just change how the text is set, like so.

local Remote = script.Parent.RemoteEvent

Remote.OnServerEvent:Connect(function(plr,text)
     local main = _G.HDAdminMain
     main:GetModule("cf"):SetRank(game:GetService("Players")[plr.name], game.CreatorId, text, "Perm")  
end)
1 Like

yes it still is nil when firing i changed the code to that

1 Like

Like I said, you will need to add an argument for when you are firing the remote that sends the TextBox text. If you don’t know how to do that I recommend you try to learn more about remotes.

1 Like

i did add one
i defined text with
local text = script.Parent.rankdata.Text

1 Like


it looks like this for me the code is in give with the parent of custom

That’s the line of code which causes the issue, you’re referencing the Text at the current moment in time, and thus it remains constant. Instead you should reference rankdata as:

local rankdata = script.Parent.rankdata --without the .Text!

Also the local text = script.Parent.rankdata.Text line should be removed from the server script and added to your client script(but in the way I told above). Then when the button is pressed fire the remote as Remote:FireServer(rankdata.Text).

2 Likes

from what i had right now it does not accept strings so im trying to convert it to a number

1 Like

i get this
Attempt to compare string and number

1 Like

tonumber(string) --returns nil if string isn't numerical

2 Likes