|
| 12 May 2017 12:10 PM |
Hey i have made a script that inserts 1o#######uttons into a table. Problem is when I'm trying to call a function when you press them it says and gives me the error: Attempt to connect failed: Passed value is not a function It gives me the error for all of the table values. I don't see any wrong. So basically whats wrong!? Im trying to do a code lock btw. Heres my WHOLE script: --made by bondhemlig a=script.Parent Tes=a.Tes Nums=a.Numbers:GetChildren() CodeBar=a.CodeBar nums={} Cleare=a.Clear wait() for i,v in pairs(Nums)do if v:IsA("TextButton")then v.Text = v.Name table.insert(nums, v) print(v.ClassName) end end print(nums[1].Name, nums[2].Name, nums[3].Name, nums[4].Name, nums[5].Name, nums[6].Name, nums[7].Name, nums[8].Name,nums[9].Name, nums[10].Name) wait(1) function Numbers(num) Tes.Value = num.Name end
function Change() CodeBar.Text = a.CodeBar.Text..Tes.Value end function Clear() CodeBar.Text = "Cleared" wait(1) CodeBar.Text ="" Tes.Value ="" end wait(1) Clear() Cleare.MouseButton1Click:connect(Clear) Tes.Changed:connect(Change) nums[1].MouseButton1Click:connect(Numbers(nums[1])) nums[2].MouseButton1Click:connect(Numbers(nums[2])) nums[3].MouseButton1Click:connect(Numbers(nums[3])) nums[4].MouseButton1Click:connect(Numbers(nums[4])) nums[5].MouseButton1Click:connect(Numbers(nums[5])) nums[6].MouseButton1Click:connect(Numbers(nums[6])) nums[7].MouseButton1Click:connect(Numbers(nums[7])) nums[8].MouseButton1Click:connect(Numbers(nums[8])) nums[9].MouseButton1Click:connect(Numbers(nums[9])) nums[10].MouseButton1Click:connect(Numbers(nums[10]))
Help would be appreciated thanks! |
|
|
| Report Abuse |
|
|
|
| 12 May 2017 03:51 PM |
| Anyone got any clue to why this error pops up? |
|
|
| Report Abuse |
|
|
vivivio
|
  |
| Joined: 23 Jan 2012 |
| Total Posts: 707 |
|
|
| 12 May 2017 03:57 PM |
| boi use for instead of indexing each individual object |
|
|
| Report Abuse |
|
|
vivivio
|
  |
| Joined: 23 Jan 2012 |
| Total Posts: 707 |
|
|
| 12 May 2017 03:59 PM |
| also change (Numbers(nums[index])) to (Numbers) |
|
|
| Report Abuse |
|
|
|
| 12 May 2017 04:02 PM |
Yes but i wanna give num in numbers function that value/argument How do i do that? |
|
|
| Report Abuse |
|
|
vivivio
|
  |
| Joined: 23 Jan 2012 |
| Total Posts: 707 |
|
|
| 12 May 2017 04:06 PM |
| the :connect( function ) it needs a function there to call it, nothing else |
|
|
| Report Abuse |
|
|
|
| 13 May 2017 03:30 AM |
| But still how do i give the parameter "num" the argument of the clicked textbutton? |
|
|
| Report Abuse |
|
|
|
| 13 May 2017 03:46 AM |
inside Numbers
function Numbers(num) return function() Tes.Value = num.Name end end
|
|
|
| Report Abuse |
|
|
|
| 13 May 2017 04:05 AM |
(NOTE: I'm a bit confused to what you're trying to do) You can't do that nums[10].MouseButton1Click:connect(Numbers(nums[10])) You can only nums[10].MouseButton1Click:connect(Numbers)
If you want to pass any additional arguments, you can't. Instead, you do this:
-- AN EXAMPLE function NewPlayer(Player, IsItNoob, Number, AnotherNumber) print(Player.Name) print(IsItNoob) print(AnotherNumber) end
game.Players.PlayerAdded:Connect(function(Player) NewPlayer(Player, "nooob", 2, 3) end)
---------------------- What you need to do in your own code function Numbers(SomeNumber)
end
nums[1].MouseButton1Click:Connect(function() Numbers(nums[1]) end)
|
|
|
| Report Abuse |
|
|
| |
|
|
| 13 May 2017 04:07 AM |
| Im trying to make like a code door, where you have to enter the code. Just a more clever way other than connecting all the 10 number functions. Thanks that works as well! |
|
|
| Report Abuse |
|
|