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:
01 | local frame = script.Parent |
02 |
03 | frame.Parent.Enabled = true |
04 |
05 | frame.itspartytime.Text = "its party time!" |
06 |
07 | frame.whoru.Text = "first of all, who are you?" |
08 |
09 | frame.guyA.Text = "A" |
10 | frame.guyB.Text = "B" |
11 | frame.guyC.Text = "C" |
12 | frame.guyD.Text = "D" |
13 | function selectguy(person) |
14 | frame:Destroy() |
15 | end |
16 | frame.guyA.MouseButton 1 Down:Connect(selectguy( "A" )) |
17 | frame.guyB.MouseButton 1 Down:Connect(selectguy( "B" )) |
18 | frame.guyC.MouseButton 1 Down:Connect(selectguy( "C" )) |
19 | frame.guyD.MouseButton 1 Down:Connect(selectguy( "D" )) |
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:
1 | frame.guyA.MouseButton 1 Down:Connect(selectguy) |
And check inside selectguy which button was pressed.
Or you can do this
1 | frame.guyA.MouseButton 1 Down:Connect( function () |
2 | selectguy( "A" ) |
3 | end ) |
4 | -- do this for all the buttons replacing "A". |
This is the way I set up my code when it comes to GUI's.
01 | local frame = script.Parent |
02 | frame.Parent.Enabled = true |
03 | frame.itspartytime.Text = "It's party time!" |
04 | frame.whoru.Text = "First of all, who are you?" |
05 | frame.guyA.Text = "A" |
06 | frame.guyB.Text = "B" |
07 | frame.guyC.Text = "C" |
08 | frame.guyD.Text = "D" |
09 |
10 | local function SelectGuy(Person) |
11 | print ( "Selected" ) |
12 | if frame then |
13 | frame:Destroy() |
14 | end |
15 | return Person |
The code you pasted never worked for me so I just did that instead...
When you use :Connect and want to put parameter you need :Connect(function()
01 | frame.guyA.MouseButton 1 Down:Connect( function () |
02 | selectguy( "A" ) |
03 | end ) |
04 | frame.guyB.MouseButton 1 Down:Connect( function () |
05 | selectguy( "B" ) |
06 | end ) |
07 | frame.guyC.MouseButton 1 Down:Connect( function () |
08 | selectguy( "C" ) |
09 | end ) |
10 | frame.guyD.MouseButton 1 Down:Connect( function () |
11 | selectguy( "D" ) |
12 | end ) |