How to pass over TextBox text to the server?

Basically the title, How could I pass over textbox text to the server, I’m already using remotes and its not working.

Code on the client: ↓

local PlayerToPutBountyOn = -- path to textbox.text
local Amount = -- path to textbox.text

script.Parent.MouseButton1Down:Connect(function(player)
     Remote:FireServer(PlayerToPutBountyOn, Amount)
end)

Code on the server: ↓

Remote.OnServerEvent:Connect(function(PlayerToPutBountyOn, Amount)
	print("got the remote") -- prints
	print(PlayerToPutBountyOn) -- prints as empty (like the textbox is empty)
	print(Amount) -- prints also as empty 
end)

The textbox’s are printing but they are printing empty, meaning the server thinks the textbox’s are empty even though I have written in them.

Any help appreciated!

I don’t know if this will make a difference or not, try using:

	print(tostring(PlayerToPutBountyOn))
	print(tostring(Amount))

For the client, I think just pass game.Players.LocalPlayer

I do not think ‘player’ is a parameter that is passed through in local scripts

1 Like

OH I JUST REALISED. DEFINE THE VARIABLES INSIDE THE FUNCTION!! The reason why is because you defined it when the player first joins—-naturally it’s blank

1 Like

That’s not what I’m trying to do… I’m trying to pass over text from a textbox, not the local players name.

1 Like

Yeah now I see it you need to pass Player through OnServerEvent first as the script thinks that PlayerToPutBountyOn is the Player and Amount is PlayerToPutBountyOn

1 Like

script.Parent.MouseButton1Down:Connect(function(player)
     local Amount = -- path to textbox.text 

local PlayerToPutBountyOn = -- path to textbox.text

Remote:FireServer(PlayerToPutBountyOn, Amount)
end)
1 Like

Why should it be blank if the player writes in the textbox something?

2 Likes

Because you defined the variable when the player joins. There is nothing in it when they join. You need to define the text inside the function so that it checks again when the player presses the button

Define the playertoputbountyon too

1 Like

Also for the server event, 3 parameters are passed: player, PlayerToPuttBountyOn, Amount

This is how events work in roblox

I moved both paths to the textbox’s t inside the function, but now only one of the textbox’s print what’s written inside.

1 Like

Read my latest post. It’s because you’re missing a parameter

2 Likes

So I should do this?

Remote.OnServerEvent:Connect(function(player, PlayerToPutBountyOn, Amount)

1 Like

yes, and you don’t need to do anything with ‘player’ if you do not want to see who fired the event

Also I suggest you add a debounce to avoid excessive event firing

For example, add the player into a table and remove them after x seconds. If the player fires th event again, check if they are in the table. If yes, don’t do anything. (I recommend do this on the localscript to avoid firing the event in the first place)

1 Like

I set this post as solution: ↓

All help appreciated!

1 Like
-- Client
local PlayerToPutBountyOn = -- path to textbox.text
local Amount = -- path to textbox.text

script.Parent.MouseButton1Down:Connect(function(player)
     Remote:FireServer(PlayerToPutBountyOn,Amount) -- Don't need to send in player argument as server automatically gets it.
end)

-- Server

Remote.OnServerEvent:Connect(function(playerWhoSentRemote,PlayerToPutBountyOn, Amount) -- First argument is always the player
	print("got the remote") -- prints
	print(PlayerToPutBountyOn) -- prints as empty (like the textbox is empty)
	print(Amount) -- prints also as empty 
end)
2 Likes

The playertoputbountyon Isn’t the player firing the event. It’s another player defined by the client

Yeah I misunderstood who was the player doing what for a second - it’s changed now :slight_smile:

1 Like

lol I misunderstood at first too :joy:

1 Like