Hey guys, having an issue trying to call a function from a Module script in a local script.
Module Script:
1 | function Settings.Update_Gui(Ammo, StoredAmmo) |
2 | if Settings.Gui and Settings.CanUpdateGui then |
3 | Settings.Gui.Frame.AmmoDisplay.Text = Ammo .. "|" .. StoredAmmo --Line 77 |
4 | end |
5 | end |
Local Script:
1 | local Ammo = script.Ammo -- NumberValue |
2 | local StoredAmmo = script.StoredAmmo -- NumberValue |
3 |
4 | Settings.Update_Gui(Ammo.Value, StoredAmmo.Value) |
Error: Players.Player1.Backpack.M1911.Settings:77: attempt to concatenate local 'StoredAmmo' (a nil value)
Let me know if you can figure out why I am getting this odd error or if you need a bit more information.
Thanks.
I was having this problem myself. It seems that the passed-in arguments get disordered for some reason. I resolved it by passing them in as a tuple instead and then parsing it. In your case I would do the following:
01 | function Settings.Update_Gui(...) |
02 | local tuple = { ... } |
03 | local Ammo = tuple [ 1 ] |
04 | local StoredAmmo = tuple [ 2 ] |
05 | if Ammo and StoredAmmo then |
06 | if Settings.Gui and Settings.CanUpdateGui then |
07 | Settings.Gui.Frame.AmmoDisplay.Text = Ammo .. "|" .. StoredAmmo |
08 | end |
09 | end |
10 | end |
And you don't have to change your localscript call.
Well, your first error is that ModuleScripts cannot be called by LocalScripts. Use a ServerScript to use a ModuleScript.
Your second error is that you're not waiting for the children of the script to exist, so:
1 | local StoredAmmo = script:WaitForChild( "StoredAmmo" ) |