(script.Parent.Purchase is a text button and returns nil, however firing the remote event with something other than the text button gets returned properly)
(Firing the event with a child of the button also returns nil)
That returns the name properly, however I want to make the text change to “Purchased” instead of “Purchase” and I would need the button to do that.
try to make, inside the OnServerEvent connection, a local variable like that:
local actual_button = script.Parent:FindFirstChild(button)
the script.Parent would be the parent of Purchase, so make sure script.Parent is the parent of Purchase element. I think you cannot pass the Purchase instance because RemoteEvents cannot pass arguments as instance, due to how serialization of data works
Use a remote function instead. Invoke the server with the trail you want to buy, handle the purchase on the server, then return whether or not the purchase failed back to the client, then change the button’s text on the client if the purchase succeeded.
Well the issue is occurring because the button doesn’t exist on the server. It’s being created on the client in some form. Anything created on the client won’t be replicated to the server.
It would work because if the trail was purchased, then the remote function would return true. On the client, I could check if the remote function returns true in order to change the text.
However what would change if it were a remote function instead of a remote event? The problem would still be there, as he would try to search for something inside the client
A remote function would allow you to wait for the server to process the purchase, then return a status (whether the purchase failed or not) back to the client so the client is then able to change the button’s text accordingly. You wouldn’t have to modify anything in the UI on the server (which is generally bad practice anyway)
Yes, that’s right. But he is trying to change the text’s button, right? Then what would change with rather using remote function? Remote functions return a value to be sent to the other side, but he is not trying to do this, but changing the text. But, yea, that’d be a solution to the problem, though there are many other solutions to this, ig.
He could pass the player argument, and then find the PlayerGui. He could pass the button name, instead of the instance, and then use FindFirstChild to check if it is there. Then, he would change the text.