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.
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
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
script.Parent.MouseButton1Down:Connect(function(player)
local Amount = -- path to textbox.text
local PlayerToPutBountyOn = -- path to textbox.text
Remote:FireServer(PlayerToPutBountyOn, Amount)
end)
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
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)
-- 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)