Hello! I have a event where it sends money, but I know there’s a better way to do it, I don’t want to manually write it.
Local Script
local rs = game:GetService("ReplicatedStorage")
local Shapes = rs:WaitForChild("Shapes", 60):GetDescendants()
local Spawner = workspace:WaitForChild("Spawner")
local MoneyEvent = rs.MoneyEvent
local Chance = require(rs:WaitForChild("Chance"))
local gui = script.Parent
local Button = gui.ShapeButton
local HasShape = false
local OldShape = nil
local MoneyPoints = 0
print("Everything loaded.")
Button.MouseButton1Down:Connect(function()
local Rarity = Chance.PickRarity("Rarities")
print(Rarity)
for i, v in pairs(Shapes) do
if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
local Folder_Shapes = v.Parent
if Rarity == Folder_Shapes.Name then
local RandomShape = Folder_Shapes:GetChildren()[math.random(1, #Folder_Shapes:GetChildren())]:Clone()
if HasShape ~= true then
HasShape = true
RandomShape.Parent = Spawner
RandomShape.CFrame = CFrame.new(Spawner.CFrame.X, Spawner.CFrame.Y, Spawner.CFrame.Z)
print(RandomShape)
OldShape = RandomShape
if Folder_Shapes.Name == "Common" then
MoneyPoints += 10
MoneyEvent:FireServer(MoneyPoints)
end
if Folder_Shapes.Name == "Rare" then
MoneyPoints += 30
MoneyEvent:FireServer(MoneyPoints)
end
break
elseif HasShape == true then
OldShape:Destroy()
HasShape = false
end
end
end
end
end)
Module Script
local Chance = {}
local Rarities = {
Common = 0, -- 60% chance
Rare = 0.6, -- 40% chance
Epic = 0.8, -- 20% chance
Legendary = .9, -- 10% chance
-- Mythic = 0.99, -- 1% chance
-- Unique = 0.991, -- 0.09% chance
-- Ultra = 0.995, -- 0.05% chance
-- Insane = 0.999 -- 0.01% chance
}
function Chance.PickRarity()
local Index = math.random()
local HighestRarity = "Common"
for RarityName, Value in pairs(Rarities) do
if Index >= Value and Value >= Rarities[HighestRarity] then
HighestRarity = RarityName
end
end
return HighestRarity
end
return Chance