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

What is wrong with this Module script, to local script? [Unanswered]

Asked by
Mystdar 352 Moderation Voter
10 years ago

I am trying to Weld a Model to a Player, with the Weld Function in a ModuleScript, called "ModuleFunctions", then calling it in a LocalScript. There is nothing in the Output that relays an error of any sort. These are the two scripts:

Module:

function Weld1(Object, Object_Path, Middle, Part, Part_Path)
    local Model = game[Object_Path][Object]:clone()
    Model.Parent = game.Workspace[Part_Path][Part]
    local C = Model:GetChildren()
    for i=1, #C do
        if C[i].className == "Part" or C[i].className == "Union Operation" then
            local W = Instance.new("Weld")
            W.Part0 = Model[Middle]
            W.Part1 = C[i]
            local CJ = CFrame.new(Model[Middle].Position)
            local C0 = Model[Middle].CFrame:inverse()*CJ
            local C1 = C[i].CFrame:inverse()*CJ
            W.C0 = C0
            W.C1 = C1
            W.Parent = Model[Middle]
        end
        local Y = Instance.new("Weld")
        if Part == nil then 
            Y.Part0 = game.Workspace[Part_Path]
        elseif Part ~= nil then
            Y.Part0 = game.Workspace[Part_Path][Part]
        end
        Y.Part1 = Model[Middle]
        Y.C0 = CFrame.new(0, 0, 0)
        Y.Parent = Y.Part0
    end
    local h = Model:GetChildren()
    for i = 1, # h do
        h[i].Anchored = false
        h[i].CanCollide = false
    end
end

return Weld1

Local Script:

ModuleFunction = require(game.Workspace.ModuleFunctions)

Player = game.Players.LocalPlayer
Humanoid = Player.Character:WaitforChild("Humanoid")
player = Humanoid.Parent

ModuleFunction("Hook", "Lighting", "Middle", "Right Arm", "Player1")

EDIT I have tried this Local Script too, and it hasn't worked:

ModuleFunction = require(workspace.ModuleFunctions)

Player = game.Players.LocalPlayer
Humanoid = Player.Character:WaitforChild("Humanoid")
player = Humanoid.Parent
a = game.Workspace:WaitForChild("Player1")
ModuleFunction("Hook", "Lighting", "Middle", "Right Arm", a)
0
You never returned your function in the Module script. Try adding the line 'return Weld1' to the bottom of the script. BlackJPI 2658 — 10y
0
I tried that and it didn't seem to effect anything Mystdar 352 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

You're returning the function directly, so the correct usage is actually:

ModuleFunction = require(game.Workspace.ModuleFunctions)

ModuleFunction(...)

Alternatively, you can update your Module to use a table, and return that instead:

local Exports = {}

function Exports.Weld1(...)
    -- ...
end

return Exports
0
Sorry, this didn't resolve my issue, the script still doesn't work Mystdar 352 — 10y
Ad

Answer this question