You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
So i have a button inside of a textlabel, the textlabel’s text is a player’s name(this player is also in the game)
When you click this button i want to fire a bindable event inside of the player’s PlayerGui that i want to trade with.
What is the issue? Include screenshots / videos if possible!
The problem is that it does find the player, but it indexes nil with PlayerGui! Btw PlayerGui already loaded so far and it’s done from a localscript
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I couldn’t find any solutions here or anywhere else, that’s why i need help!
Here’s what the script looks like :
script.Parent.MouseButton1Click:Connect(function()
local player1 = game.Players:FindFirstChild(script.Parent.Parent.Text)
local player2 = script.Parent.Parent.Parent.Parent.Parent
local event = player1.PlayerGui.Trade.TradeRequest – Error here
event:Fire(player1.Name, player2.Name)
end)
Make sure your variables are referenced correctly. For readability sakes and organisation, you should probably reference your player without that much .Parent
I would try chucking a WaitForChild on the PlayerGui, as well as debugging the code, e.g printing the player name, checking to see if PlayerGui is not equal to nil, etc.
So as I understand it player1 has a thing on their screen that they click which causes a thing to pop up on player2 screen?
At the moment you’re trying to directly reference a gui object of another player’s player gui which you just can’t do.
If you want to trigger something happening on another player’s screen then you’ll need to use remotes. Player1 fires a remote that tells the server to notify player2, the server then fires a remote to notify player2 about what’s going on. Player2 then handles the pop up themselves.
I think you haven’t understood what I’ve said. I’ll go through the code and comment where things will break because of the server-client boundary / replication restrictions.
script.Parent.MouseButton1Click:Connect(function()
local player1 = game.Players:FindFirstChild(script.Parent.Parent.Text) -- Player 1 is a different player than the one running this script
local player2 = script.Parent.Parent.Parent.Parent.Parent -- Player 2 is the local player
local event = player1.PlayerGui.Trade.TradeRequest -- Player 1's playerGui is not visible to player 2 (who is the one running this script) so anything within player1's player gui is not replicated to player 2
event:Fire(player1.Name, player2.Name)
end)
Is there any other way i can use bindable events outside of the playergui for this? or does it have to be a remote event? I’m making a trading system and it requires aclot of client-to-client communication.
Is there even a trading system tutorial in general? If there is that would be really helpful, because then I know how they made client-to-client communication without 20 remote events just for simply showing a frame and some pets inside of it.
Any client to client communication needs to go through the server somehow and the way that is done in scripts like this is with remotes. You don’t need a lot of remotes to make this work as you can make use of the arguements that you can pass when you fire / invoke a remote.
I imagine there’s probably a tutorial around somehow on how to do it but I can’t remember seeing any that I can link here right now unfortunately.