How do I get my module scripts to work while using require?

What I want to achieve is to insert a new rig into a player MID-game.

FYI (I use requires for this so it inserts it into the server)

  1. So ill start from the top. I have two Modules that move the UI and StarterCharacter into certain spots.
    image
    This is the code for the custom character.
local module = {}

function module.MainUI(target)
    _G.target = target
    local target = game.Players:WaitForChild(_G.target)
   	script.StarterCharacter:Clone().Parent = game.StarterPlayer
end

return module

Heres my code for UI (The UI works on its own when I used require or add it into StarterGUI. But the module for StarterPlayer doesn’t work) --The module scripts are basically the same–

local module = {}

function module.MainUI(target)
    _G.target = target
    local target = game.Players:WaitForChild(_G.target)
    script.MainUI:Clone().Parent = target.PlayerGui
end

return module

I’ve search for at least 3 hours and found nothing.

So to wrap it all up, I just need the modules to do what they are meant to do, and be able to change the player mid-game.

I’m not asking anyone to make it for me, but help me on what to do so I can understand next time I do something similar. (It’s your choice if you want to or not)

You can message me here : Itz_N3p#6105

From what I can see you have 2 modules named the same, and 2 functions named the same. Maybe try naming your modules and functions with unique names and see if that helps.

2 Likes

Hm, I tried that and it didn’t work.

Use a humanoid description, changing the starter character is probably not a good idea.

1 Like

I think change function module.MainUi(target) to Module.MainUi = function(target)

Also, to call a Module, you must do the Following:

local M = require("Put module location here, like game.Workspace.ModuleScript")
M.MainUi(target)

Hope I helped!
1 Like