I have created a script that when a player looks at an object it then displays a BillboardGui to let the player know how to interact with an object. Now the issue is that on the server side it cannot find the BillboardGui at all. The following are snippets of my code.
On the Client side the player requests for an "interaction interface" or the BuildboardGui to show up in front of them telling them something like "[E]" on the object. Ignore the "false" as it is unnecessary to refer to it as it has nothing to do with the issue.
local request = game.ReplicatedStorage.Request_InteractionView:InvokeServer(object, false); if (not request) then warn("Error with viewing!"); end
On the server, it copies a ready-made BillboardGui to the object itself to display to the player. Notice that the GUI takes the name of the player and adds "_GUI" to the end of it. Also, if returning true isn't defined then by default it should return false -- which means an error occurred.
local GUI = game.ReplicatedStorage.Assets.GUI:Clone(); GUI.HoverText.Text = "[E] OPEN DOOR"; GUI.Parent = Object; GUI.Name = tostring(Plr.Name .. "_GUI"); return true;
Now back on the client side it sends another request once the player looks away (moves their pointer away) from the object.
local request = game.ReplicatedStorage.Request_InteractionView:InvokeServer(object, true); if (not request) then warn("Error with resetting view!"); end
And back on the server, it checks whether or not there is an object named "player name + '_GUI'" -- which actually should exist as it has been created earlier when looking at the door -- and returns true once it has successfully executed.
if (Object:FindFirstChild(tostring(Plr.Name .. "_GUI"))) then Object[tostring(Plr.Name .. "_GUI")]:Destroy(); return true; end warn("Unable to find GUI to remove.");
Unfortunately, this never happens and returns false by default as it has failed to execute (since returning a value completely halts the rest of the script to run). This means that it could not find the exactly-named BillboardGui at all. Once checking, I noticed it created multiple BillboardGuis into the object (making a weird-looking text) and none of them were ever removed.
Any help in resolving this issue is very much appreciated!
I had solved my issue. I instead placed the GUI within the object using a LocalScript. This allows me to only display the GUI only towards the player. Not just that but as well was able to find the GUI stored within the object by keeping it stored in a variable within the LocalScript.