How would I pass the player name from a FireClient/OnClientEvent

Hello everyone, so I need to pass in the player name from a script to the client with a remote even or something. But it just doesn’t work and instead makes it nil. How could I fix that?
All help is appreciated :happy3:

This is the local script who gets the name of the player(OnClientEvent):

game.ReplicatedStorage.SystemText.PlayerJoinSystem.OnClientEvent:Connect(function(plr)
	bc = BrickColor.new("Institutional white")
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "Welcome to Tunnel Of Heck "..player.Name.."!!!";
		Font = Enum.Font.Cartoon;
		Color = bc.Color;
		FontSize = Enum.FontSize.Size96;
	})
end)

And this is the script who fires the OnClientEvent(FireClient):

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("WinSaveSystem")
local ds2 = datastore:GetDataStore("CurrencySaveSystem")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "leaderstats"
	
 local ShopItemsFolder = Instance.new("Folder", plr)
 ShopItemsFolder.Name = "ShopItemsMutators"	
	
 local wins = Instance.new("IntValue", folder)
 wins.Name = "Wins"
	
 local currency = Instance.new("IntValue", folder)
 currency.Name = "ParkourCoins"
	
 local invisivility	= Instance.new("NumberValue")
 invisivility.Name = "invisivilityMutator"
 invisivility.Parent = ShopItemsFolder	
	
 wins.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, wins.Value)

 currency.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, currency.Value)
	
 game.ReplicatedStorage.SystemText.PlayerJoinSystem:FireClient(plr)
end)

I would gladly appreciate any help, format it in your own ways any help is fine :slight_smile:

A quick google search would give you information on remove events.

1 Like

The first argument of FireClient is the target player. By doing FireClient(plr) you’re firing the remote to that specific player only, with 0 params.

If you want to display the message to everyone, replace FireClient in your code with FireAllClients.

3 Likes

I tried that but it dosent show how to pass the player form a script to a local script :confused:

oh, so if example I want players to see who bought something I would use fire all clients?

What are you trying to do? I’m a bit confused here.
OnServerEvent takes in 2 arguments, (player – who fired the event, and **args) inf args

I am using OnClientEvent not OnServerEvent I am trying to get the player’s name trough a script into a local script

1 Like

Err, no.
Assuming you have a shop system, it would go something like this.

  • player buys something in shop
  • shop fires a remote event to the server saying we want to buy something
  • server receives remote event and gives the player what they want

If you want to fire to the server, just use FireServer()
Then, on the script that handles the server side, just use

[remoteEvent].OnServerEvent:Connect(function(plr)

end)
1 Like

tho its a system text script I want to display in the chat to everyone who bought an Item.


local player = game:GetService("Players"):FindFirstChild(plr)

if player then
      game.ReplicatedStorage.SystemText.PlayerJoinSystem:FireClient(player)
end

Try get player object.

1 Like

could work but I am trying to get a specific player, the player who bought the item and then display it in the chat as a system message. Tho I will try your answer :slight_smile:

I just explained that above. Please try checking the API reference before asking anymore questions. Everything you need to know about Remote Events are there.

Edit:

  • FireServer(**args) takes in optional arguments
  • OnServerEvent(player, **args) takes in the player who fired the event and the optional arguments provided.
1 Like

I checked every API reference before this post and in all of them there is no talking about getting the player name from the script/server script and passing it to the client so the client can use it and show in the chat that this player bought an item.

You’re missing the point of op’s question. They want all players to receive the OnClientEvent sent to them from the server. They do not want help with setting up a shop system, and replying with just a wiki link once is enough, no need to do it twice.

@Grayuu once again, just replace this line in your code

game.ReplicatedStorage.SystemText.PlayerJoinSystem:FireClient(plr)

with this:

game.ReplicatedStorage.SystemText.PlayerJoinSystem:FireAllClients(plr)

As FireClient takes the target player as the first argument, doing remote:FireClient(plr, "hello") will make OnClientEvent of plr receive "hello" as the first argument.
On the other hand, doing remote:FireAllClients("hello") will make the OnClientEvent of all players receive "hello" as the first argument.

Edit: also change player.Name to plr.Name in your localscript’s code to reflect the param name

2 Likes

alr, I will try that right now thx for helping me you guys :slight_smile:

yes it works so now all players will see who bought an item right?

If you set up your localscript properly then yes. You can test it by using the 2 players test feature of roblox studio
image

2 Likes

alr I’l try that right now. (30 Charssssss)

Edit: btw thx for helping me dude