Hello! I have this shape rarity, but it doesn’t delete after they click again. Please help!
local rs = game:GetService("ReplicatedStorage")
local Shapes = rs:WaitForChild("Shapes", 5):GetDescendants()
local Spawner = workspace:WaitForChild("Spawner")
local Chance = require(rs:WaitForChild("Chance"))
local gui = script.Parent
local Button = gui.ShapeButton
Button.MouseButton1Down:Connect(function()
local Rarity = Chance.PickRarity("Rarities")
for i, v in pairs(Shapes) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
local Folder_Shapes = v.Parent
if Rarity == Folder_Shapes.Name then
local HasShape = false
local RandomShape = Folder_Shapes:GetChildren()[math.random(1, #Folder_Shapes:GetChildren())]:Clone()
if not HasShape then
HasShape = true
print(Rarity)
print(HasShape)
RandomShape.Parent = Spawner
RandomShape.CFrame = CFrame.new(Spawner.CFrame.X, Spawner.CFrame.Y + 5, Spawner.CFrame.Z)
print(RandomShape.CFrame)
print(RandomShape)
break
elseif HasShape then
RandomShape:Destroy()
HasShape = false
print("False")
end
end
end
end
end)
local rs = game:GetService("ReplicatedStorage")
local Shapes = rs:WaitForChild("Shapes", 5):GetDescendants()
local Spawner = workspace:WaitForChild("Spawner")
local Chance = require(rs:WaitForChild("Chance"))
local gui = script.Parent
local Button = gui.ShapeButton
local HasShape = false
Button.MouseButton1Down:Connect(function()
local Rarity = Chance.PickRarity("Rarities")
for i, v in pairs(Shapes) do
if v:IsA("BasePart") or v:IsA("MeshPart") 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 not HasShape then
HasShape = true
print(Rarity)
print(HasShape)
RandomShape.Parent = Spawner
RandomShape.CFrame = CFrame.new(Spawner.CFrame.X, Spawner.CFrame.Y + 5, Spawner.CFrame.Z)
print(RandomShape.CFrame)
print(RandomShape)
break
else
RandomShape:Destroy()
HasShape = false
print("False")
end
end
end
end
end)
Hi! Remember you again lol (thanks for the help btw). Yeah it relies on a 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
}
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
No problem! I didn’t have to change your ModuleScript, but I did tinker with your LocalScript code. Try this:
local rs = game:GetService("ReplicatedStorage")
local Shapes = rs:WaitForChild("Shapes", 60):GetDescendants()
local Spawner = workspace:WaitForChild("Spawner")
local Chance = require(rs:WaitForChild("Chance"))
local gui = script.Parent
local Button = gui.ShapeButton
local HasShape = false
local OldShape = nil
print("Everything loaded.")
Button.MouseButton1Down:Connect(function()
local Rarity = Chance.PickRarity("Rarities")
print("rare")
for i, v in pairs(Shapes) do
if v:IsA("BasePart") or v:IsA("MeshPart") 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
print(Rarity)
print(HasShape)
RandomShape.Parent = Spawner
RandomShape.CFrame = CFrame.new(Spawner.CFrame.X, Spawner.CFrame.Y + 5, Spawner.CFrame.Z)
print(RandomShape.CFrame)
print(RandomShape)
OldShape = RandomShape
break
elseif HasShape == true then
OldShape:Destroy()
HasShape = false
print("False")
end
end
end
end
end)