Function Parameter Not Passing Properly

Hello developers, I am currenly working on a script and I am trying to pass a parameter value to a function but the parameter goes as nil to the other function. How can I fix this problem? Here is the script:

local Player = game.Players.LocalPlayer

local InteractiveGuiAssets = workspace:WaitForChild("InteractiveGuiAssets")

local StationManagementProximityPrompt = InteractiveGuiAssets:WaitForChild("StationManagementPaper")

local function ProximityTriggered(Player, prox)
	print(prox.Name)
end

for _, InteractiveAsset in pairs(InteractiveGuiAssets:GetChildren()) do
	print(InteractiveAsset.Name) -- not nil
	InteractiveAsset:WaitForChild("ProximityPrompt")
	print(InteractiveAsset.ProximityPrompt.Parent) -- not nil
	InteractiveAsset.ProximityPrompt.Triggered:Connect(ProximityTriggered, Player, InteractiveAsset.ProximityPrompt)  -- The second parameter always gives the player so I put my object to the third parameter
end

:Connect() only accepts one parameter, and that is the function. That function receives any arguments .Triggered passes (same goes for Players.PlayerAdded, UIS.InputBegan etc.).

If you want to pass additional params, call your function within that function.

InteractiveAsset.ProximityPrompt.Triggered:Connect(function(player)
	ProximityTriggered(player, InteractiveAsset.ProximityPrompt)
end)

Thanks for the reply, it works fine now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.