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

Calling Module function from a Local script?

Asked by
Necrorave 560 Moderation Voter
9 years ago

Hey guys, having an issue trying to call a function from a Module script in a local script.

Module Script:

function Settings.Update_Gui(Ammo, StoredAmmo)
    if Settings.Gui and Settings.CanUpdateGui then
        Settings.Gui.Frame.AmmoDisplay.Text = Ammo .. "|" .. StoredAmmo --Line 77
    end
end

Local Script:

local Ammo = script.Ammo -- NumberValue
local StoredAmmo = script.StoredAmmo -- NumberValue

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.

1
For whatever reason, StoredAmmo is not being passed to the Update_Gui function. Use some print() statements on both sides of the function call (inside and outside the Module script) to see at what point you're losing the data. adark 5487 — 9y

2 answers

Log in to vote
0
Answered by 6 years ago

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:

function Settings.Update_Gui(...)
    local tuple = {...}
    local Ammo = tuple[1]
    local StoredAmmo = tuple[2]
    if Ammo and StoredAmmo then
        if Settings.Gui and Settings.CanUpdateGui then
            Settings.Gui.Frame.AmmoDisplay.Text = Ammo .. "|" .. StoredAmmo
        end
    end
end

And you don't have to change your localscript call.

Ad
Log in to vote
-2
Answered by 9 years ago

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:

local StoredAmmo = script:WaitForChild("StoredAmmo")
0
Hmm, Module Script cannot intereact with local scripts? Interesting. Can you provide a link to that? It doesnt mention that on the module script roblox page. Necrorave 560 — 9y
0
Also, as a side note. The second bit of information is not the problem. Thanks for the idea though. Necrorave 560 — 9y
0
ModuleScripts can totally be used normally by localscripts. There is no limitation there. BlueTaslem 18071 — 9y
0
Thought so. Thanks @BlueTaslem Necrorave 560 — 9y
View all comments (4 more)
0
? I read on wiki... can you please not downvote? I got it wrong cause I read it on the wiki... TheDeadlyPanther 2460 — 9y
0
Where did you read this 'fact' on the wiki? It's 100% wrong, and I'll be glad to change it if you can link me to it. adark 5487 — 9y
0
Also, you can remove your answer if it gets negative attention or is incorrect. Just for future reference Necrorave 560 — 9y
0
OK, will do. Sorry about this :P I believe I read a sentence in the description of how to use them, interpreting it as 'cannot be used by localscripts' TheDeadlyPanther 2460 — 9y

Answer this question