ReplicatedStorage remote event help

Ello, this is just a quick question. How do you get the username of the player who fired a RemoteEvent?

Asking because I am making a announcement system and I want it to say “Notification from (user)”

If it’s a FireServer, OnServerEvent's first Parameter is the player who fired the event

RemoteEvent.OnServerEvent:Connect(function(player)
    print(player.Name)
end)
RemoteEvent:FireServer()

If it’s a FireClient, get the local player in the localscript with OnClientEvent

Mines OnClientEvent, because its in a local script.

In your case, when you FireClient, you can tell who fired the Event via getting the Players.LocalPlayer and then get their name.

Unless you’re doing a FireAllClients, if you already have the player in that case on the server, pass in their name and then do stuff with it

1 Like

I tried that, when I did the studio test with player 1 & 2 it showed their own name for each window and did not work.

Then it’s a problem in how you’re causing the announcement to happen

How are you triggering the FireClient?

When you fire the client, make sure you put Player.Name as a parameter.

Here’s my code. the tweens are so the ui fades in and out, could it be because its a local script??

RemoteEvent.OnClientEvent:Connect(function(text, player)
	TextLabel.Text = text
	

	local TextTransparency = TweenService:Create(TextLabel, TweenInfo.new(1, Enum.EasingStyle.Quint), {TextTransparency = 0})
	TextTransparency:Play()
	
	local TextTransparency2 = TweenService:Create(title, TweenInfo.new(1, Enum.EasingStyle.Quint), {TextTransparency = 0})
	TextTransparency2:Play()

	local BackgroundTransparency = TweenService:Create(frame, TweenInfo.new(1, Enum.EasingStyle.Quint), {BackgroundTransparency = 0})
	BackgroundTransparency:Play()
	
	local TextTransparency2 = TweenService:Create(title, TweenInfo.new(1, Enum.EasingStyle.Quint), {TextTransparency = 0})
	TextTransparency2:Play()
	
	local BackgroundTransparency = TweenService:Create(line, TweenInfo.new(1, Enum.EasingStyle.Quint), {BackgroundTransparency = 0})
	BackgroundTransparency:Play()

	task.wait(5)
	
	local TextTransparency = TweenService:Create(TextLabel, TweenInfo.new(1, Enum.EasingStyle.Quint), {TextTransparency = 1})
	TextTransparency:Play()
	
	local TextTransparency2 = TweenService:Create(title, TweenInfo.new(1, Enum.EasingStyle.Quint), {TextTransparency = 1})
	TextTransparency2:Play()

	local BackgroundTransparency = TweenService:Create(frame, TweenInfo.new(1, Enum.EasingStyle.Quint), {BackgroundTransparency = 1})
	BackgroundTransparency:Play()
	
	local BackgroundTransparency = TweenService:Create(line, TweenInfo.new(1, Enum.EasingStyle.Quint), {BackgroundTransparency = 1})
	BackgroundTransparency:Play()
end)

Can you show the code that fires this RemoteEvent

script.Parent.MouseButton1Click:Connect(function()
	local textbox = script.Parent.Parent.Announce.Text
		
	game.ReplicatedStorage.AnnounceEvent:FireServer(textbox)
	
end)

This fires it.

What fires the client? Can you show us?

Already posted it above, please help! :slight_smile:

No, you didn’t. I mean can you show us the script that fires the client?

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local RemoteEvent = ReplicatedStorage.AnnounceEvent

--//Functions
RemoteEvent.OnServerEvent:Connect(function(player, text)
	RemoteEvent:FireAllClients(text)
end)

Make sure you label the player in your :FireClient() event

Pass in player.Name after the text

RemoteEvent.OnServerEvent:Connect(function(player, text)
	RemoteEvent:FireAllClients(text, player.Name)
end)

And in the OnClientEvent, change TextLabel.Text = text to however you want, could be something like

TextLabel.Text = player .. " Announced:  " .. text

as an example

Yeah, I agree with them, but just make sure you instance the player in your first parameter.

That’s for FireClient, they’re using FireAllClients which doesn’t need that

How would I get “player” in the main local script?

You already did, you put player as a parameter in the OnClientEvent, passing the name after the text in the FireAllClients is enough