i tried:
(the brick script)
script.Parent.MouseClick:Connect(function(player) game.ReplicatedStorage.RemoteEvent:FireClient(player) end)
(in the gui local script)
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(player) script.Parent.Text = "the food has been found, and "..player.Name.." found it"
end)
when i click the brick, it just ignores the player.Name string and says "the food has been found, and.
im just not sure what to do, any type of help would be great.
RemoveEvent:FireClient() takes a player as the first argument. This is the client that will "receive the event" if that makes sense.
RemoveEvent.OnClientEvent() already knows who that player is (it's the local player who is listening to that event) and therefore, does not have have it as an argument. But it does have everything that was passed after that. (In your case nothing was, so it was nil, which is why your text came out that way)
For example, passing "Hello, world!" after specifying which client you want to fire for like so:
RemoveEvent:FireClient(player, "Hello, world!")
Will be handled like so in the local script:
RemoveEvent.OnClientEvent:Connect(text) -- First argument is not the player, but the arguments passed after -- In this case, the text print(text) -- Prints "Hello, world!" end)
Based on what you're trying to do, I am assuming you want all the players' Gui change based on whoever clicks the brick. For that, there is a handy member function of RemoveEvents, which is :FireAllClients(). Since you're sending a signal to all clients, you do not need to specify a specific one. Just pass in the arguments directly.
So for your case, this how it would look like:
-- Brick script (normal script) script.Parent.MouseClick:Connect(function(player) -- Since the name is all you need, I would suggest just passing that in game.ReplicatedStorage.RemoteEvent:FireAllClients(player.Name) end)
Here is your Gui script:
-- This should be a local script game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(name) script.Parent.Text = "the food has been found, and ".. name.." found it" end)
I would recommend reading up on the API references for RemoveEvents here: https://developer.roblox.com/en-us/api-reference/class/RemoteEvent