Need a quick help with this seemingly simple problem to functions

Activating this function works fine:

ProximityIsKey.Triggered:Connect(NotSoDooDoo)

Adding a parameter to it and all of a sudden it wants to be funny and pretend it don’t know what I’m talking about:

ProximityIsKey.Triggered:Connect(NotSoDooDoo(ProximityIsKey))

Anyone know why this is the case? If you want the whole code I can send it.

3 Likes

What are you trying to do?

local function NotSoDooDoo(player)
--code
end

ProximityIsKey.Triggered:Connect(NotSoDooDoo)

This should work and you can get the proximity with how you got ProximityIsKey in the first place.

2 Likes

This is the rest of my code:

local function NotSoDooDoo(KanyeWest)
	print("fein")
end

local function DooDoo(greenfn, poop)
	local ProximityIsKey = Instance.new("ProximityPrompt")
	ProximityIsKey.HoldDuration = 2
	ProximityIsKey.Parent = greenfn
	ProximityIsKey.ActionText = "Goon"
	if poop == "One" then
		greenfn.Humanoid:MoveTo(ConcessionLine:FindFirstChild("Cashier1").Position)
		greenfn.Humanoid.MoveToFinished:Wait()
		greenfn.HumanoidRootPart.Orientation = Vector3.new(0,90,0)
	else if poop == "Two" then
			greenfn.Humanoid:MoveTo(ConcessionLine:FindFirstChild("Cashier2").Position)
			greenfn.Humanoid.MoveToFinished:Wait()
			greenfn.HumanoidRootPart.Orientation = Vector3.new(0,0,0)
		end
	end
	ProximityIsKey.Triggered:Connect(NotSoDooDoo(ProximityIsKey))
end

The reason why I want a parameter passed is because in the function I want to :Destroy() the ProximityPrompt. (Ignore my brainrot)

1 Like

Have you tested if the proximity prompt does anything if triggered?

1 Like

You cannot directly pass parameters into the Connect function of an RBXScriptSignal. You will have to create a new function that will call your function with your own parameters:

local function triggered(proximityPrompt, player)
	if proximityPrompt == openDoor then
		-- do stuff
	end
end

openDoor.Triggered:Connect(function(player)
	triggered(openDoor, player)
end)

When you do Connect(foo(...)), what you are actually doing is calling the function foo and connecting whatever that function returns, whatever that may be.

local function foo(a)
    return a
end

proximityPrompt.Triggered:Connect(foo(1))
-- incorrect usage. equivalent to:
proximityPrompt.Triggered:Connect(1)
-- giving you an error of:
-- Attempt to connect failed: Passed value is not a function
1 Like

For you guys that care this is what I decided to do:

local function DooDoo(greenfn, poop)
	local ProximityIsKey = Instance.new("ProximityPrompt")
	ProximityIsKey.HoldDuration = 2
	ProximityIsKey.Parent = greenfn
	ProximityIsKey.ActionText = "Goon"
	if poop == "One" then
		greenfn.Humanoid:MoveTo(ConcessionLine:FindFirstChild("Cashier1").Position)
		greenfn.Humanoid.MoveToFinished:Wait()
		greenfn.HumanoidRootPart.Orientation = Vector3.new(0,90,0)
	else if poop == "Two" then
			greenfn.Humanoid:MoveTo(ConcessionLine:FindFirstChild("Cashier2").Position)
			greenfn.Humanoid.MoveToFinished:Wait()
			greenfn.HumanoidRootPart.Orientation = Vector3.new(0,0,0)
		end
	end
	ProximityIsKey.Triggered:Connect(function()
		ProximityIsKey:Destroy()
	end)
end
1 Like