Sometimes it doesn't clone

Hello! Sometimes the part doesn’t clone to the workspace. This happens more commonly with the epic, and higher up rarity. Please help!

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 Rarities = {
	["Common"] = {
		MoneyPoints = 10
	},
	["Rare"] = {
		MoneyPoints = 20
	},
	["Epic"] = {
		MoneyPoints = 50
	},
	["Legendary"] = {
		MoneyPoints = 120
	},
	["Mythic"] = {
		MoneyPoints = 250
	},
	["Unique"] = {
		MoneyPoints = 500
	},
}

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
					
					MoneyEvent:FireServer(Rarities[Folder_Shapes.Name].MoneyPoints)

					break

				elseif HasShape then

					OldShape:Destroy()
					HasShape = false
				end
			end
		end

	end
end)

Button.MouseButton1Down:Connect(function()
	Button.Visible = false
	task.wait(.25)
	Button.Visible = true
	
end)
2 Likes

Hello!! Would you mind sharing the PickRarity function? There is a chance that the bug has something to do with that script.

1 Like

Hello! Sure thing!

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.9% chance
	-- Ultra = 0.995, -- 0.5% chance
	-- Insane = 0.999 -- 0.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

This issue still persist and I can’t find a fix

it’s because HasShape is true. eitherway i dont know.
do you get any errors?

No errors, it only happens when I get an Epic or above, it prints the rarity but doesn’t clone the shape. This is annoying because if this doesn’t get fixed, I won’t be able to release the game.

Here’s a picture of the output.

image

Code:

local rs = game:GetService("ReplicatedStorage")
local Shapes = rs:WaitForChild("Shapes", 60):GetDescendants()

local Spawner = workspace:WaitForChild("Spawner", 10)
local MoneyEvent = rs.MoneyEvent
local Chance = require(rs:WaitForChild("Chance"))

local gui = script.Parent
local Button = gui.ShapeButton

local Rarities = {
	["Common"] = {
		MoneyPoints = 10
	},
	["Rare"] = {
		MoneyPoints = 20
	},
	["Epic"] = {
		MoneyPoints = 50
	},
	["Legendary"] = {
		MoneyPoints = 120
	},
	["Mythic"] = {
		MoneyPoints = 250
	},
	["Unique"] = {
		MoneyPoints = 500
	},
	["Ultra"] = {
		MoneyPoints = 1e3
		
	}
}

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
			print("Passes  CheckPoint 1")
			if Rarity == Folder_Shapes.Name then

				local RandomShape = Folder_Shapes:GetChildren()[math.random(1, #Folder_Shapes:GetChildren())]:Clone()
				print("Checkpoint 2")
				if HasShape ~= true then
					HasShape = true
					print("Checkpoint 3")
					RandomShape.Parent = Spawner
					RandomShape.CFrame = CFrame.new(Spawner.CFrame.X, Spawner.CFrame.Y + 3, Spawner.CFrame.Z)

					print(RandomShape)
					OldShape = RandomShape
					
					MoneyEvent:FireServer(Rarities[Folder_Shapes.Name].MoneyPoints)

					break

				elseif HasShape then
					print("Deletion")
					OldShape:Destroy()
					HasShape = false
				end
			end
		end

	end
end)

Button.MouseButton1Down:Connect(function()
	Button.Visible = false
	task.wait(.25)
	Button.Visible = true
	
end)

im guessing this is the output when it doesn’t clone. it doesnt clone because you did not set the parent of the cloned instance. so you have to figure out how to use HasShape properly so you get the desired output.

Yeah…that’s what I need help with.

Atlas, I had to pay someone to fix it for me.

local rs = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players").LocalPlayer
local Remotes = rs.Remotes
local Shapes = rs:WaitForChild("Shapes", 60):GetDescendants()

local Spawner = workspace:WaitForChild("Spawner", 10)
local Chance = require(rs:WaitForChild("Chance"))

local gui = script.Parent
local Button = gui.ShapeButton

local Rarities = {
	["Common"] = {
		MoneyPoints = 10
	},
	["Rare"] = {
		MoneyPoints = 20
	},
	["Epic"] = {
		MoneyPoints = 50
	},
	["Legendary"] = {
		MoneyPoints = 120
	},
	["Mythic"] = {
		MoneyPoints = 250
	},
	["Unique"] = {
		MoneyPoints = 500
	},
	["Ultra"] = {
		MoneyPoints = 1e3
	}
}

local OldShape
local MoneyPoints = 0

print("Everything loaded.")

Button.MouseButton1Down:Connect(function()
	Button.Visible = false
	task.wait(.25)
	Button.Visible = true

	
	if OldShape then
		OldShape:Destroy()
		OldShape = nil
	end

	local Rarity = Chance.PickRarity("Rarities")
	print(Rarity)
	for i, v in pairs(Shapes) do
		local Folder_Shapes = v.Parent
		if v:IsDescendantOf(Folder_Shapes) then
			print("Passes CheckPoint 1")
			if Rarity == Folder_Shapes.Name then
				local RandomShape = Folder_Shapes:GetChildren()[math.random(1, #Folder_Shapes:GetChildren())]:Clone()

				RandomShape.Parent = Spawner
				RandomShape.CFrame = CFrame.new(Spawner.CFrame.X, Spawner.CFrame.Y + 3, Spawner.CFrame.Z)

				OldShape = RandomShape

				Remotes.AwardMoney:FireServer(Rarities[Folder_Shapes.Name].MoneyPoints)
				break  
			end
		end
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.