Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how do i make it so when you click a click detector, your name will appear on the gui?

Asked by 3 years ago
Edited 3 years ago

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.

1 answer

Log in to vote
0
Answered by
Mineloxer 187
3 years ago

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

0
Wow!! I really understand it more now!! Thank you for the help! SmellyCarlover 12 — 3y
0
No problem, glad I could help! Mineloxer 187 — 3y
Ad

Answer this question