Attempt to concatenate nil with string

Hello! I am trying to make it so, whenever a player earns a badge, it will be sent in chat. Like this: User1 has received the badge 'Example Badge'!

The problem is, when I connect it with a remote event (like usual), it will pop this error up:

I’ve tried searching through different posts and solutions, nothing matches what I am trying to do and none of them work.

  • Script:
game.ReplicatedStorage:WaitForChild("SendBadgeGivenEvent").OnClientEvent:Connect(function(none, plr, badge)
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = plr.. " has earned the badge " .. badge .. "!",
		Color = Color3.fromRGB(54, 163, 163)
	})
end)

Example of event fired:

game.SendBadgeGivenEvent:FireAllClients("example1", "example2")

You’re passing parameters none, plr, badge which in order will receive example1, example2, nil thus “badge” will be nil
Server → client event firing doesn’t pass the initial parameter for the sending player, which may be why you were voiding the first parameter with “none”

You may also check that plr and badge are non-nil strings before printing?

Yep, correct, I tried voiding with the parameter “none”.

And I have printed the 2 parameters plr and badge, which did were not nil, and actually printed the string.

1 Like

Would string formatting with some default strings help? is plr a string for their name, or the player instance?
Text = string.format("%s has earned the badge %s!", plr and plr or "A player", badge and badge or "A badge")

plr is infact a string for their name.

One example of it can be used like this:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
 game.ReplicatedStorage.SendBadgeGivenEvent:FireAllClients(plr.Name, "Clicked")
end)

which will show up to others like this:
Pixelctrl has earned the badge 'Clicked'!.

And I’ve tried the formatting method, it did not work, and nothing has printed in the console.

Remove the parameter named “none”.

You’re only passing two values as arguments to the FireAllClients() call so only two values will be received on the listening side by the corresponding .OnClientEvent event.

Done after @MP3Face mentioned it.

This is my current script:

game.ReplicatedStorage:WaitForChild("SendBadgeGivenEvent").OnClientEvent:Connect(function(plr, badge)
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = string.format("%s has earned the badge %s!", plr and plr or "A player", badge and badge or "A badge"),
		Color = Color3.fromRGB(54, 163, 163)
	})
end)

After moments of debugging and fixing (for 22+ days), I have fixed it

The fix was adding 3 arguments; (plr, name, badge)

Then, just firing the 2nd and 3rd argument. It apparently worked and sent in chat.
Thanks for whoever tried to help!