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

Is it possible to pass an object from localscript to ModuleScript without an event?

Asked by 9 years ago

First of all, I have filtering enabled, and everything was working fine till I tried what I'm doing below:

I have some functions I was using within both my server scripts and local scripts. I wanted to consolidate them all to a modulescript.

I thought I could do this within a local script:

                            local UT =  require(game.ReplicatedStorage.UtilityCode)
                            local model_tool = part.Parent.Parent:Clone()
                            local original_name = model_tool.Name
                            model_tool.Name = model_tool.Name.."-"..player.Name
                            model_tool.Parent = game.ReplicatedStorage

                            game.ReplicatedStorage:WaitForChild(model_tool.Name)

                            model_tool.Name = original_name

                            local tool_in_model = UT:get_tool_from_object(model_tool)
                            local GAME_CONFIG = tool_in_model.Game_Config:Clone()

but when I try to do a getChildren on the model_tool object passed into my modulescript, there is an error message saying that the argument passed in is nil, even though I check it for a nil value before it gets that far.

I'm using RemoteFunctions and RemoteEvents, otherwise, but just wanted to try getting around some of that with 3 simple functions I use that I can otherwise make into RemoteFunctions for both Server and Client... Maybe those remote functions could just call my modulescript at that point.

Any thoughts?

-Jason

0
ModuleScripts are only started on the server once, and once for each client. Seperately. Are you aware of this fact? iaz3 190 — 9y
0
Yes I'm using it accordingly JasonTheOwner 391 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Well, I was stubborn, kept testing some obvious things, and as it turned out, my best option was to use tuple on my expected arguments, and it was the second argument of the table that gave me the start of the results, in all cases. I was able to pass in an object to my module script, and used the functions with both my local and server scripts.

Here's a portion of what worked:

local UtilityCode = {}
UtilityCode.obj = {}
function UtilityCode.get_tool_from_object(...)

    local tuple = {...}
    local obj = tuple[2]
    local result = nil
    if obj==nil then
        return result
    end

    local c= obj:getChildren()
    for i,v in pairs(c) do
        if v:IsA("Tool") then
            result = v
        end
    end
    return result
end
return UtilityCode
Ad

Answer this question