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
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
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
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.
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
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