RemoteEvents Assistance

I have recently came back on ROBLOX to script and the one thing I find to struggle with is RemoteEvents. I understand somewhat of the concept but what I want to seek an answer for is how can I transfer player information from one place to another.

Let me stretch it out a bit. If you go to my other topic I recently wrote, I asked on how I can make a certain GUI appear on a certain player. I want to use the same idea and add it something else.

If anyone doesn’t mind explaining how information, or in this case, a player’s name, can be transferred from one place to another.

If I am understanding correctly, you want to pass info to different places within the same game?

Well, kind of yeah. I am trying to make a feature where if a player touches a certain part, a text from a billboard GUI gets changed into the player’s name.

Well, you wouldn’t need a RemoteEvent for that.

local part = (Part)

part.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
        --It's a player
        local chr = hit.Parent
        local plr = game.Players:GetPlayerFromCharacter(chr)
        local textLabel = (textLabel in billboard gui)
        textLabel.Text = plr.Name
    end
end)

Edit: Unless you want the billboard gui text to be seen only by the player and nobody else

So, how would it work if it was only meant to be seen on the player’s screen?

You could change that script to a LocalScript if you want it to be client-sided (Or visible to you only and not to everyone else)

Just make sure to define your Part where it is & put it inside StarterPlayerScripts

Then you would have to fire a remoteevent to the player.

Create a RemoteEvent in ReplicatedStorage(presumably in a folder), and name it something like “BillboardDetection”

Then, in a regular script, put this:

local part = (Part)

part.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	
	if hum then
		local chr = hit.Parent
		local plr = game.Players:GetPlayerFromCharacter(chr)
		local textLabel = (textLabel)
		game.ReplicatedStorage.BillboardDetect:FireClient(plr,textLabel)
	end
end)

In a localscript, put this


game.ReplicatedStorage.BillboardDetect.OnClientEvent:Connect(function(textLabel)
	textLabel.Text = game.Players.LocalPlayer.Name
end)

Thank you for informing on my issue but I also do want to learn from this so I have a question. When I fire an event, what do I put in the parenthesis. Like the example given, why was the second argument in the regular script, textLabel and the first argument in the LocalScript, “textLabel”

When you are firing a RemoteEvent from a server script, you have 2 options:

RemoteEvent:FireClient(certainPlr) – Fires to a specific player, specification needed

RemoteEvent:FireAllClients() --Fires to all players, no specification needed

Pretend the first argument is like a direction to the server on which player to fire to


When you are firing a RemoteEvent from a local script to the server, you would just put your parameters

RemoteEvent:FireServer([parameters])

However, when receiving this from a server script, you need to include the player who fired the remote event as the first argument

RemoteEvent.OnServerEvent(plrWhoFiredTheEvent, [parameters])

Could you give an example for RemoteEvent:FireClient

Since the server doesn’t know what player to exactly look for, you need to pass a Player object when using FireClient()

game.Players.PlayerAdded:Connect(function(Player)
    game.ReplicatedStorage.RemoteEvent:FireClient(Player, WhateverElse)
end)

Doing it like this:

game.Players.PlayerAdded:Connect(function(Player)
    game.ReplicatedStorage.RemoteEvent:FireClient(WhateverElse)
end)

How would the server know which player to fire this to? :thinking:

Ahh, this makes more sense, thank you.