#module script thing im confused

1 messages · Page 1 of 1 (latest)

hybrid kestrel
#

Ill send everything you need

#

**Characters Module ==> **```local Module = {}
local Characters = {}
local CharacterRarity = {}

local rarityInfo = {
{"Common"; 2; Color3.fromRGB(120, 255, 124)},
{"Rare"; 5; Color3.fromRGB(0, 170, 255)},
{"Epic"; 7; Color3.fromRGB(170, 0, 255)},
{"Legendary"; 10; Color3.fromRGB(255, 255, 0)},
{"Mythic"; 13; Color3.fromRGB(170, 0, 0)},
{"Felon"; 16; Color3.fromRGB(255, 174, 11)},
{"Kingpin"; 20; Color3.fromRGB(170, 0, 127)},
}

for _, rarity in script:GetChildren() do
if rarity:IsA("Folder") then
for _, character in rarity:GetChildren() do
Characters[character.Name] = character
CharacterRarity[character.Name] = rarity.Name
end
end
end

local function GetRarityColor (rarityName)
for _, data in pairs(rarityInfo) do
if data[1] == rarityName then
return data[3]
end
end

return Color3.new(1,1,1)

end

function Module.CloneCharacter(Name: string, Parent: Instance)
local CloneNPC = Characters[Name]:Clone()
CloneNPC.Parent = Parent

local rarity = CharacterRarity[Name]
local rarityColor = GetRarityColor(rarity)

local ClonedHInfo = script.HeadInfo:Clone()
ClonedHInfo.Parent = CloneNPC.Head
ClonedHInfo.Criminal = CloneNPC.Name
ClonedHInfo.Price = "$ ".. CloneNPC:GetAttribute("Price")
ClonedHInfo.Effect = CloneNPC:GetAttribute("Production").."/s"
ClonedHInfo.Rarity = rarity
ClonedHInfo.Rarity.TextColor3 = rarityColor
return CloneNPC

end

return Module```

#

CharacterSpawner ==> ```local Characters = require(game.ReplicatedStorage:WaitForChild("Characters"))
local SharedBases = require(game.ServerStorage:WaitForChild("SharedBases"))
local NPCPath = game.Workspace.NPCPath

local rarityInfo = {
{"Common"; 2; Color3.fromRGB(120, 255, 124)},
{"Rare"; 5; Color3.fromRGB(0, 170, 255)},
{"Epic"; 7; Color3.fromRGB(170, 0, 255)},
{"Legendary"; 10; Color3.fromRGB(255, 255, 0)},
{"Mythic"; 13; Color3.fromRGB(170, 0, 0)},
{"Felon"; 16; Color3.fromRGB(255, 174, 11)},
{"Kingpin"; 20; Color3.fromRGB(170, 0, 127)},
}

local function GetRandomRarity ()
for i, v in ipairs(rarityInfo) do
local RandomNumber = math.random(1, v[2])
if RandomNumber == 1 and v[2] > rarityInfo[1][2] then
return{
v[1],
v[2]
}

    end
end

return rarityInfo[1]

end

while task.wait(3) do
local RandomRarity = GetRandomRarity()
local CharacterModels = game.ReplicatedStorage.Characters[RandomRarity[1]]
local RandomNumber = math.random(1, #CharacterModels:GetChildren())

local CloneNpc: Model = Characters.CloneCharacter(CharacterModels:GetChildren()[RandomNumber].Name, NPCPath, workspace.CurrentCharacters)
local CHumanoid: Humanoid = CloneNpc:FindFirstChildWhichIsA("Humanoid")
local CTorso: Part = CloneNpc:FindFirstChild("Torso")

if not CTorso then
    CloneNpc:Destroy()
end

CloneNpc:PivotTo(NPCPath.Start.CFrame)

CHumanoid:MoveTo(NPCPath.Stop.CFrame)

end```

#

Errors ==> 16:45:59.927 ServerScriptService.CharacterSpawner:33: invalid argument #2 to 'random' (interval is empty) - Server - CharacterSpawner:33

#

need help on tis

fossil crescent
#

sorry i cant read it, its not in format 😭

#
local Characters = require(game.ReplicatedStorage:WaitForChild("Characters"))
local SharedBases = require(game.ServerStorage:WaitForChild("SharedBases"))
local NPCPath = game.Workspace.NPCPath

local rarityInfo = {
    {"Common"; 2; Color3.fromRGB(120, 255, 124)},
    {"Rare"; 5; Color3.fromRGB(0, 170, 255)},
    {"Epic"; 7; Color3.fromRGB(170, 0, 255)},
    {"Legendary"; 10; Color3.fromRGB(255, 255, 0)},
    {"Mythic"; 13; Color3.fromRGB(170, 0, 0)},
    {"Felon"; 16; Color3.fromRGB(255, 174, 11)},
    {"Kingpin"; 20; Color3.fromRGB(170, 0, 127)},
}

local function GetRandomRarity ()
    for i, v in ipairs(rarityInfo) do
        local RandomNumber = math.random(1, v[2])
        if RandomNumber == 1 and v[2] > rarityInfo[1][2] then
            return{
                v[1],
                v[2]
            }
            
        end
    end
    
    return rarityInfo[1]
end

while task.wait(3) do
    local RandomRarity = GetRandomRarity()
    local CharacterModels = game.ReplicatedStorage.Characters[RandomRarity[1]]
    local RandomNumber = math.random(1, #CharacterModels:GetChildren())
    
    local CloneNpc: Model = Characters.CloneCharacter(CharacterModels:GetChildren()[RandomNumber].Name, NPCPath, workspace.CurrentCharacters)
    local CHumanoid: Humanoid = CloneNpc:FindFirstChildWhichIsA("Humanoid")
    local CTorso: Part = CloneNpc:FindFirstChild("Torso")
    
    if not CTorso then
        CloneNpc:Destroy()
    end
    
    CloneNpc:PivotTo(NPCPath.Start.CFrame)
    
    CHumanoid:MoveTo(NPCPath.Stop.CFrame)
    
    
end
#

ok there we go

#

hold on

hybrid kestrel
#

local RandomNumber = math.random(1, #CharacterModels:GetChildren())

#

mb

#

?

fossil crescent
#

oh

#

i see now

fossil crescent
hybrid kestrel
#

yes

fossil crescent
#

Screenshot your CharacterModels folder

#

is it actually empty?

hybrid kestrel
#

Well actually

#

I identify the CharacterModels using the random rarity function

fossil crescent
#

oh so its not a folder

hybrid kestrel
#

local CharacterModels = game.ReplicatedStorage.Characters[RandomRarity[1]]

fossil crescent
hybrid kestrel
#

but i think its not getting the actual things

fossil crescent
#

have you ever Debugged it yet?

hybrid kestrel
#

let me try

fossil crescent
# hybrid kestrel

Uhhh there is no characters in Common, Epic, Legendary, Mythic, or Rare at all

#

Check if they actually get the folder first before the "actual things"

hybrid kestrel
#
    local RandomRarity = GetRandomRarity()
    local CharacterModels = game.ReplicatedStorage.Characters[RandomRarity[1]]
    
    if CharacterModels then

        local RandomNumber = math.random(1, #CharacterModels:GetChildren())

        local CloneNpc: Model = Characters.CloneCharacter(CharacterModels:GetChildren()[RandomNumber].Name, NPCPath, workspace.CurrentCharacters)
        local CHumanoid: Humanoid = CloneNpc:FindFirstChildWhichIsA("Humanoid")
        local CTorso: Part = CloneNpc:FindFirstChild("Torso")

        if not CTorso then
            CloneNpc:Destroy()
        end

        CloneNpc:PivotTo(NPCPath.Start.CFrame)

        CHumanoid:MoveTo(NPCPath.Stop.CFrame)
    else
        warn("No character mOdel")
    end
    
    
    
end```
#

sorry how do i format it so that you can read it

fossil crescent
hybrid kestrel
#

oh by the way

#

the charactermodels is not nil

#

it has it but

#

16:57:34.499 ServerScriptService.CharacterSpawner:36: invalid argument #2 to 'random' (interval is empty) - Server - CharacterSpawner:36

#

line 36

#
local Characters = require(game.ReplicatedStorage:WaitForChild("Characters"))
local SharedBases = require(game.ServerStorage:WaitForChild("SharedBases"))
local NPCPath = game.Workspace.NPCPath

local rarityInfo = {
    {"Common"; 2; Color3.fromRGB(120, 255, 124)},
    {"Rare"; 5; Color3.fromRGB(0, 170, 255)},
    {"Epic"; 7; Color3.fromRGB(170, 0, 255)},
    {"Legendary"; 10; Color3.fromRGB(255, 255, 0)},
    {"Mythic"; 13; Color3.fromRGB(170, 0, 0)},
    {"Felon"; 16; Color3.fromRGB(255, 174, 11)},
    {"Kingpin"; 20; Color3.fromRGB(170, 0, 127)},
}

local function GetRandomRarity ()
    for i, v in ipairs(rarityInfo) do
        local RandomNumber = math.random(1, v[2])
        if RandomNumber == 1 and v[2] > rarityInfo[1][2] then
            return{
                v[1],
                v[2]
            }
            
        end
    end
    
    return rarityInfo[1]
end

while task.wait(3) do
    local RandomRarity = GetRandomRarity()
    local CharacterModels = game.ReplicatedStorage.Characters[RandomRarity[1]]
    
    if CharacterModels then

        local RandomNumber = math.random(1, #CharacterModels:GetChildren())

        local CloneNpc: Model = Characters.CloneCharacter(CharacterModels:GetChildren()[RandomNumber].Name, NPCPath, workspace.CurrentCharacters)
        local CHumanoid: Humanoid = CloneNpc:FindFirstChildWhichIsA("Humanoid")
        local CTorso: Part = CloneNpc:FindFirstChild("Torso")

        if not CTorso then
            CloneNpc:Destroy()
        end

        CloneNpc:PivotTo(NPCPath.Start.CFrame)

        CHumanoid:MoveTo(NPCPath.Stop.CFrame)
    else
        warn("No character mOdel")
    end
    
    
    
end```
#

let me explain it maybe

#

so

#

i have the GetRandomRarity()

#

to get the NAME of the model

#

then i look for it in the Characters Module script

#

here

fossil crescent
hybrid kestrel
#

no warning

sonic rapidsBOT
#

studio** You are now Level 8! **studio

hybrid kestrel
#

at all

fossil crescent
#

no like

#
print(CharacterModels)
hybrid kestrel
#

yes

#

it prints

#

here

#

i have an idea

#

ill add an template npc in every rarity

#

it worked