anyone know why this could be happening?
lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local unitsFolder = ReplicatedStorage:WaitForChild("Units")
local CharacterHandler = {}
--RARITY TABLE------------------------------
local rarityChances ={
Common = 50,
Uncommon = 25,
Rare = 13,
Epic = 6.5,
Legendary = 4,
Mythic = 1,
Secret = 0.5,
}
local function rollRarity()
local roll = math.random(1, 100)
local counter = 0
for rarity, chance in pairs(rarityChances) do
counter += chance
if roll <= counter then
return rarity
end
end
return "Common"
end
function CharacterHandler.UpdateOverheadUI(character, rarity)
if game.Players:GetPlayerFromCharacter(character) then
return
end
local config = character:WaitForChild("Config")
local price = config:FindFirstChild("Price")
local moneyGen = config:FindFirstChild("MoneyGen")
local headlineUI = ReplicatedStorage:WaitForChild("HeadlineUI"):Clone()
headlineUI.Parent = character
headlineUI.Adornee = character:WaitForChild("AttatchUI")
if price and moneyGen then
local priceLabel = headlineUI:WaitForChild("Price")
local moneyLabel = headlineUI:WaitForChild("MoneyGeneration")
local nameLabel = headlineUI:WaitForChild("CharacterName")
local rarityLabel = headlineUI:WaitForChild("Rarity")
priceLabel.Text = "$" .. price.Value
moneyLabel.Text = "$" .. moneyGen.Value .. "/s"
nameLabel.Text = character.Name
rarityLabel.Text = rarity
if rarity == "Common" then
rarityLabel.TextColor3 = Color3.fromRGB(100, 100, 100)
elseif rarity == "Uncommon" then
rarityLabel.TextColor3 = Color3.fromRGB(0, 255, 0)
elseif rarity == "Rare" then
rarityLabel.TextColor3 = Color3.fromRGB(0, 0, 255)
elseif rarity == "Epic" then
rarityLabel.TextColor3 = Color3.fromRGB(128, 0, 128)
elseif rarity == "Legendary" then
rarityLabel.TextColor3 = Color3.fromRGB(255, 215, 0)
elseif rarity == "Mythic" then
rarityLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
elseif rarity == "Secret" then
rarityLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
end
headlineUI.Enabled = true
else
warn("PriceValue and MoneyGenValue do not exist.")
return
end
end
function CharacterHandler.SpawnCharacter(rarity)
rarity = rarity or rollRarity()
local rarityFolder = unitsFolder:FindFirstChild(rarity)
if not rarityFolder then
warn("No rarity folder found for:", rarity)
return
end
local unitOptions = rarityFolder:GetChildren()
if #unitOptions == 0 then
warn("No units found inside rarity:", rarity)
end
local unit = unitOptions[math.random(1, #unitOptions)]
local clone = unit:Clone()
clone:PivotTo(workspace.Conveyor:WaitForChild("start").CFrame)
clone.Parent = workspace
CharacterHandler.UpdateOverheadUI(clone, rarity)
local config = clone:WaitForChild("Config")
local walk = config:WaitForChild("Walk")
local animtrack = clone.Humanoid.Animator:LoadAnimation(walk)
animtrack.Looped = true
animtrack:Play()
local hum = clone:FindFirstChild("Humanoid")
if hum then
local destination = workspace.Conveyor:WaitForChild("end").Position
hum:MoveTo(destination)
hum.MoveToFinished:Connect(function()
if (clone.HumanoidRootPart.Position - destination).Magnitude < 10 then
clone:Destroy()
else
hum:MoveTo(destination)
end
end)
end
end
return CharacterHandler