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())