Is adding an additional parameter to a connected function possible?

Hey, I have a question. Is it possible to add a second paramater to the PlayerAdded function (or any other event)?

I may have explained that terribly, but here is an example script.

-- this is an example script to explain my question

local players = game:GetService("Players")
local PrintText = "TestMessage" -- I want this to be warned

-- I want print_text to be set as PrintText, by just connecting the playeradded.
local function PlayerAdded(player: Player, print_text: string)
	if print_text ~= nil then
		warn(tostring(print_text))
	else
		warn("No print text")
	end
end

players.PlayerAdded:Connect(PlayerAdded) -- can i add another paramater to this, without creating a new function?
-- playeradded gives the player, and i want it to give the print text as well in this example.

The easy way i can think of is this, but i was just wondering if there was a better way without making another function. I assume theres not much benefit, but its been annoying me so i thought i would ask.

players.PlayerAdded:Connect(function(Player: Player)
	PlayerAdded(Player, PrintText)
end)

Thanks in advance

Yeah its pretty annoying but the only alternative is to create a separate function:

players.PlayerAdded:Connect(function(Player: Player)
	PlayerAdded(Player, PrintText)
end)

You cant add an additional parameter to a connected function!

2 Likes