Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years 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:

01local frame = script.Parent
02 
03frame.Parent.Enabled = true
04 
05frame.itspartytime.Text = "its party time!"
06 
07frame.whoru.Text = "first of all, who are you?"
08 
09frame.guyA.Text = "A"
10frame.guyB.Text = "B"
11frame.guyC.Text = "C"
12frame.guyD.Text = "D"
13function selectguy(person)
14frame:Destroy()
15end
16frame.guyA.MouseButton1Down:Connect(selectguy("A"))
17frame.guyB.MouseButton1Down:Connect(selectguy("B"))
18frame.guyC.MouseButton1Down:Connect(selectguy("C"))
19frame.guyD.MouseButton1Down:Connect(selectguy("D"))

3 answers

Log in to vote
0
Answered by 5 years 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:

1frame.guyA.MouseButton1Down:Connect(selectguy)

And check inside selectguy which button was pressed.

Or you can do this

1frame.guyA.MouseButton1Down:Connect(function()
2    selectguy("A")
3end)
4-- do this for all the buttons replacing "A".
Ad
Log in to vote
0
Answered by 5 years ago

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

01local frame = script.Parent
02frame.Parent.Enabled =true
03frame.itspartytime.Text = "It's party time!"
04frame.whoru.Text = "First of all, who are you?"
05frame.guyA.Text = "A"
06frame.guyB.Text = "B"
07frame.guyC.Text = "C"
08frame.guyD.Text = "D"
09 
10local function SelectGuy(Person)
11    print("Selected")
12    if frame then
13        frame:Destroy()
14    end
15    return Person
View all 29 lines...

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

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
5 years ago

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

01frame.guyA.MouseButton1Down:Connect(function()
02    selectguy("A")
03end)
04frame.guyB.MouseButton1Down:Connect(function()
05    selectguy("B")
06end)
07frame.guyC.MouseButton1Down:Connect(function()
08    selectguy("C")
09end)
10frame.guyD.MouseButton1Down:Connect(function()
11    selectguy("D")
12end)

Answer this question