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)
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)