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

Having trouble requesting modules?

Asked by 8 years ago

I'm trying to make a module for my prison, but when ever I try to request it, I get the error of, requested module experienced an error while loading

My request script

require(434418787)
_PrisonServices.AssignTeam(game.Players.PlayerAdded,"New yeller")

My module named MainModule

local _PrisonServices = {}
local authorisedServers = {
    [431532864] = true;
}

if authorisedServers[game.PlaceId] then

    local children = script:GetChildren()
    script = Instance.new("ModuleScript")
    for _, child in pairs(children) do
        child.Parent = script
    end

    script = nil
    --Teaming Services

    function _PrisonServices.AssignTeam(player,teamColor)
        if game.Players:FindFirstChild(player) ~= nil then
            player.TeamColor = BrickColor.new(teamColor)
            player.Character.Humanoid.Health = 0
        elseif player.Character ~= nil then
            player.TeamColor = BrickColor.new(teamColor)
            player.Character.Humanoid.Health = 0
        end
    end

    --Admin Services
     --TBA
    --Control Services
     --TBA
    return _PrisonServices
else
    Msg = Instance.new("Message",workspace)
    Msg.Text = "You have not paid for this service. Please contact TheHospitalDev to purchase"
    repeat
        warn'You have not paid for this service'
        wait(5)
    until authorisedServers == 0
end

Any help is appreciated.

1 answer

Log in to vote
0
Answered by 8 years ago

Your server script.

if game:GetService("RunService"):IsStudio() then -- I added this in in case someone gets mad for the module erroring.
    error("[Module-Teaming]: Your in studio, the module may error! Although it won't in a game server!")
end
local Module            =require(434418787) -- You needed to make the module a variable.
Module:AssignTeam(game.Players.PlayerAdded, "New yeller") -- And your old module function was not correct.

And your now fixed module..

local _PrisonServices           ={}
local authorisedServers         ={
    [431532864]=true;
}
local Enabled                   =false

if authorisedServers[game.PlaceId] then
    Enabled = true
else
    Enabled = false
end

function _PrisonServices:AssignTeam(player, teamColor)
    if Enabled then
        if game.Players:FindFirstChild(tostring(player),true) ~= nil then
            player.TeamColor = BrickColor.new(teamColor)
            player.Character.Humanoid.Health = 0
        else
            warn("Unable to find user")
        end
    else
        local Msg = Instance.new("Hint",workspace) -- Hint instance is less annoying then a Message.
        Msg.Text = "You have not paid for this service. Please contact TheHospitalDev to purchase"
        repeat
            warn'You have not paid for this service'
            wait(5)
        until potato -- Yolo it
    end
end

script.Parent = nil
return(_PrisonServices ) -- You needed to return this table. All modules require it.
0
P.S. I designed it to be annoying so it is unplayable if you didn't pay :P TheHospitalDev 1134 — 8y
Ad

Answer this question