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

(Module Script) Not working? [Edited]

Asked by 9 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

I have this module script(Intended to give a player a custom morph when they spawn, cloning the model morph, into a players character and welding It to the players body) but its not working, NO errors, and doesn't do anything. Module Code:

local module = {}

function module.MorphPlayer(char, morph)
    local settings = require(script.Settings)
    local m = morph:Clone()
    m.Parent = char
    for i, v in pairs(m:GetChildren()) do
        if v:FindFirstChild("MainPart") then
            for i, p in pairs(v:GetChildren()) do
                if p.Name ~= "MainPart" then
                    local w = Instance.new("Weld", p)
                    w.Part0 = v.MainPart
                    w.Part1 = p
                    w.C1 = p.CFrame:inverse() * v.MainPart.CFrame
                    Instance.new("BodyForce", p).force = Vector3.new(0, p:GetMass() * 196.2, 0)
                    p.Anchored = false
                else
                    if p:FindFirstChild("face") then
                        p.face:Destroy()
                    end
                    p.Anchored = false
                    p.Transparency = 1
                    p.CanCollide = false
                    local w = Instance.new("Weld", p)
                    w.Part0 = char[v.Name]
                    w.Part1 = p
                end
            end
        end
        if settings.RemoveHats then
            if v:IsA("Hat") then
                v:Destroy()
            end
        end
        if settings.RemoveCharacterMeshes then
            if v:IsA("CharacterMesh") then
                v:Destroy()
            end
        end
        if settings.RemoveClothes then
            if v:IsA("Shirt") or v:IsA("Pants") then
                v:Destroy()
            end
        end
    end
end

return module

Code for running module(Inside serverscriptservice)

local Morph = require(game.ReplicatedStorage.MorphModule)

    game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function(character)
            Morph.MorphPlayer(character, game.ReplicatedStorage.Morph)
        end)
    end)

1 answer

Log in to vote
0
Answered by 9 years ago

For your module code, you'll want to keep the module's global at the top or create a new one. Then convert your module's function to a global function using the modulescript's global that we create. At then you'll want to return the global instead of the function.

local module = {}

function module.MorphPlayer(char, morph)
    local settings = require(script.Settings)
    local m = morph:Clone()
    m.Parent = char
    for i, v in pairs(m:GetChildren()) do
        if v:FindFirstChild("MainPart") then
            for i, p in pairs(v:GetChildren()) do
                if p.Name ~= "MainPart" then
                    local w = Instance.new("Weld", p)
                    w.Part0 = v.MainPart
                    w.Part1 = p
                    w.C1 = p.CFrame:inverse() * v.MainPart.CFrame
                    Instance.new("BodyForce", p).force = Vector3.new(0, p:GetMass() * 196.2, 0)
                    p.Anchored = false
                else
                    if p:FindFirstChild("face") then
                        p.face:Destroy()
                    end
                    p.Anchored = false
                    p.Transparency = 1
                    p.CanCollide = false
                    local w = Instance.new("Weld", p)
                    w.Part0 = char[v.Name]
                    w.Part1 = p
                end
            end
        end
        if settings.RemoveHats then
            if v:IsA("Hat") then
                v:Destroy()
            end
        end
        if settings.RemoveCharacterMeshes then
            if v:IsA("CharacterMesh") then
                v:Destroy()
            end
        end
        if settings.RemoveClothes then
            if v:IsA("Shirt") or v:IsA("Pants") then
                v:Destroy()
            end
        end
    end
end

return module

After this, we go back to your script that calls it. You'll want to require the modulescript as you already do, then call it using the same identifier. You'll need to include the function with it that you are calling from the modulescript.

local Morph = require(game.ReplicatedStorage.MorphModule)

    game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function(character)
            Morph.MorphPlayer(character, game.ReplicatedStorage.Morph)
        end)
    end)

0
I used these codes you provided, its still not working as intended? any ideas? ghosteffectz 115 — 9y
0
Something in your modulescript is halting. It's called correctly now as I fixed that. It looks like you have another module script running. Is that one called correctly also? Syntax correct? Has it's global as I said? Legoman654 100 — 9y
0
This is the only two scripts running, no nothing else ghosteffectz 115 — 9y
Ad

Answer this question