Attempt to connect failed, passed value is not a function

This script was working fine until I defined the functions themselves instead of just putting them inside the connect part. The error it returns upon clicking one of the text buttons (“A” and “B”) is “attempt to call a nil value”.

local a = script.Parent.A
local b = script.Parent.B
local frame = script.Parent
local event = game.ReplicatedStorage.Trials.MajorityRules

local function answerA()
	event:FireServer("A")
	frame:TweenPosition(UDim2.fromScale(.275,1.249), "Out", "Quad", 0.5)
end

local function answerB()
	event:FireServer("B")
	frame:TweenPosition(UDim2.fromScale(.275,1.249), "Out", "Quad", 0.5)
end

event.OnClientEvent:Connect(function(prompt)
	if prompt == "ask" then
		frame:TweenPosition(UDim2.fromScale(.275,.249), "Out", "Quad", 0.5)
	elseif prompt == "recall" and frame.Position == UDim2.fromScale(.275, .249)then
		if math.random() >= 0.5 then
			answerA()
		else
			answerB()
		end
	end
end)

a.Activated:Connect(answerA())
b.Activated:Connect(answerB())
1 Like

I see these, maybe remove the empty parameters of A & B?

2 Likes

You’re calling the function instead of just passing it. As @Jackscarlett said, remove the parenthesis.

a.Activated:Connect(answerA)
b.Activated:Connect(answerB)

oops I can’t believe I did that

Ahaha :sweat_smile: You’re fine, we all make silly mistakes from time to time

1 Like