Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Attempt to connect failed: Passed value is not a function error with GUI buttons?

Asked by 6 days ago

i run me code, it instantly says in output: 07:51:07.514 - Attempt to connect failed: Passed value is not a function 07:51:07.515 - Stack Begin 07:51:07.515 - Script 'Players.codingMASTER398.PlayerGui.ScreenGui.Frame.Script', Line 12 07:51:07.515 - Stack End 07:51:07.516 - Attempt to connect failed: Passed value is not a function 07:51:07.516 - Stack Begin 07:51:07.517 - Script 'Players.codingMASTER398.PlayerGui.ScreenGui.Frame.Script', Line 13 07:51:07.517 - Stack End 07:51:07.520 - Attempt to connect failed: Passed value is not a function 07:51:07.521 - Stack Begin 07:51:07.521 - Script 'Players.codingMASTER398.PlayerGui.ScreenGui.Frame.Script', Line 14 07:51:07.522 - Stack End 07:51:07.522 - Attempt to connect failed: Passed value is not a function 07:51:07.522 - Stack Begin 07:51:07.523 - Script 'Players.codingMASTER398.PlayerGui.ScreenGui.Frame.Script', Line 15 07:51:07.523 - Stack End 07:51:17.754 - attempt to call a nil value (x4). how can i fix this? code:

local frame = script.Parent

frame.Parent.Enabled = true

frame.itspartytime.Text = "its party time!"

frame.whoru.Text = "first of all, who are you?"

frame.guyA.Text = "A"
frame.guyB.Text = "B"
frame.guyC.Text = "C"
frame.guyD.Text = "D"
function selectguy(person)
frame:Destroy()
end
frame.guyA.MouseButton1Down:Connect(selectguy("A"))
frame.guyB.MouseButton1Down:Connect(selectguy("B"))
frame.guyC.MouseButton1Down:Connect(selectguy("C"))
frame.guyD.MouseButton1Down:Connect(selectguy("D"))

3 answers

Log in to vote
0
Answered by 6 days ago

That's because you are calling the function inside the parameters of :Connect. You have to pass the name of the function.

You have two options.

Connect the events like this:

frame.guyA.MouseButton1Down:Connect(selectguy)

And check inside selectguy which button was pressed.

Or you can do this

frame.guyA.MouseButton1Down:Connect(function()
    selectguy("A")
end)
-- do this for all the buttons replacing "A".
Ad
Log in to vote
0
Answered by 6 days ago

This is the way I set up my code when it comes to GUI's.

local frame = script.Parent
frame.Parent.Enabled =true
frame.itspartytime.Text = "It's party time!"
frame.whoru.Text = "First of all, who are you?"
frame.guyA.Text = "A"
frame.guyB.Text = "B"
frame.guyC.Text = "C"
frame.guyD.Text = "D"

local function SelectGuy(Person)
    print("Selected")
    if frame then
        frame:Destroy()
    end
    return Person
end

frame.guyA.MouseButton1Click:Connect(function()
    selectGuy("A")
end)
frame.guyB.MouseButton1Click:Connect(function()
    selectGuy("B")
end)
frame.guyC.MouseButton1Click:Connect(function()
    selectGuy("C")
end)
frame.guyD.MouseButton1Click:Connect(function()
    selectGuy("D")
end)

The code you pasted never worked for me so I just did that instead...

Log in to vote
0
Answered by
OnaKat 446 Moderation Voter
6 days ago

When you use :Connect and want to put parameter you need :Connect(function()

frame.guyA.MouseButton1Down:Connect(function()
    selectguy("A")
end)
frame.guyB.MouseButton1Down:Connect(function()
    selectguy("B")
end)
frame.guyC.MouseButton1Down:Connect(function()
    selectguy("C")
end)
frame.guyD.MouseButton1Down:Connect(function()
    selectguy("D")
end)

Answer this question