Script Refuses to Clone Children to Backpack!

alright so where is the part which the player does not get his/her cloned weapons?

did you actually write a part of that code that puts your values into leaderstats?

This script was for S0MBRX , there is nothing wrong with it , but in a different script if you check above , I need to make sure the objectValue is in the inventory before that script can run.

1 Like

are there any code may be delaying the script because there are incoming datastore requests? if so then i suggest you put the loading player values on the first part ofthe script and then the last part are their datastores

1 Like

Like I said before this script is for when they click the spin button , it then fires an event to another script here that adds the value to the leaderstats

--Deduct price
		local leaderstats = player.leaderstats
		local stat = leaderstats.Spins
		stat.Value = stat.Value - contents.Price
		
		--Generate Crate Details and Winning Item
		local winningCrateId = contents.Crates - 5
		local winningItem = items[winningCrateId]
		
		
		--Check if duplicate, if not, reward item
		local duplicate = false
		if contents.DuplicateReward and leaderstats.Inventory:FindFirstChild(winningItem.Name) then
			duplicate = true
			leaderstats.Trys.Value = leaderstats.Trys.Value + itemTypes[winningItem.GroupIndex].Rarity.DuplicateReward
		else
			local newStat = Instance.new("ObjectValue")
			newStat.Name = winningItem.Name
			newStat.Parent = leaderstats.Inventory
		end

		--Returns spin details
		return {
			["Items"] = items;
			["WinningCrateId"] = winningCrateId;
			["WinningItem"] = winningItem;
			["Duplicate"] = duplicate;
		}
		
	end
end
1 Like

I haven’t added datatstore yet , I need to grasp the concept of it before thinking of adding it to my script , so it shouldn’t be there.

1 Like

i think you should just start a new topic for this new problem because the soloution for this topic has been achieved and its just getting a little messy in here

And here is the module script that has the name, rarity, colour etc of what the value, frame and chance to get is.
It’s just there to give the name of the value and other properties.


-- << CONFIGURATION >>
contents["Price"] = 1;

contents["Crates"] = 45;
contents["SpinTimeBounds"] = {7,8}
contents["SpinEasingStyle"] = Enum.EasingStyle.Quart;
contents["SpinEasingDirection"] = Enum.EasingDirection.Out;
contents["SpinDirection"] = "Right";

contents["DuplicateReward"] = false; -- Set to true to receive the 'DuplicateReward' for already-owned items. Set to false to receive the item again. 
contents["EliminateOwnedItems"] = false; -- Set to true to remove already-owned items from the spinner. 

contents["Messages"] = {
	Loading 				= "Loading...";
	FailPermissionCheck 	= "Not enough Spins!";
	ServerError				= "Error!";
	ServerErrorComplete		= "Error: unlocked all possible items!";
	RewardNewItem			= "Your Magic is...";
	RewardDuplicate1		= function(a) return("Duplicate "..a.."!") end; -- where 'a' is the RarityName
	RewardDuplicate2		= function(a) return("+"..a.." Spins") end; -- where 'a' is the DuplicateCashReward
}



-- << PERMISSION CHECK >>
function contents:PermissionToSpin(player)
	local leaderstats, Spins = player:FindFirstChild("leaderstats")
	if leaderstats then
		Spins = leaderstats:FindFirstChild("Spins")
	end
	if Spins and Spins.Value >= contents.Price then
		return true
	else
		return false
	end
end



-- << ITEMS AND RARITIES >>	
function contents:GetItemTypes()
	local itemTypes = {
		-----------------------------------
		{
		Rarity = {Name = "Common",		Chance = 0.8, 	Color = Color3.fromRGB(170, 170, 255),	DuplicateReward = 0};
		Items = {
			
			{Name = "Fire", ImageId = 2419083546};
			{Name = "Water", ImageId = 1468821126};
			{Name = "Earth", ImageId = 2643944686};
			{Name = "Wind", ImageId = 1468821305};
			{Name = "Lightning", ImageId = 1468822149};
			}
		
		};
		-----------------------------------
		{
		Rarity = {Name = "Uncommon",	Chance = 0.12, 	Color = Color3.fromRGB(43,125,43),	DuplicateReward = 0};
		Items = {
			
			{Name = "Ice", ImageId = 1468821620};
			{Name = "Magma", ImageId = 1801056307};
			{Name = "Metal", ImageId = 2419083419};
			{Name = "Wood", ImageId = 1468820879};
			{Name = "Sand", ImageId = 2643944712};
			}
		
		};
		-----------------------------------
		{
		Rarity = {Name = "Rare",		Chance = 0.06, 	Color = Color3.fromRGB(210,85,0),	DuplicateReward = 0};
		Items = {
			
			{Name = "Light", ImageId = 1471365373};
			{Name = "Dark", ImageId = 1468818998};
			{Name = "Blue Fire", ImageId = 1468820407};
			{Name = "Explosion", ImageId = 2570569323};
			{Name = "Amaterasu", ImageId = 1468820383};
			{Name = "Acid", ImageId = 1468820383};
			}
		
		};
		-----------------------------------
		{
		Rarity = {Name = "Legendary",	Chance = 0.015, 	Color = Color3.fromRGB(170,0,0),	DuplicateReward = 0};
		Items = {
			
			{Name = "Crimson Lion", ImageId = 2419084522};
			{Name = "Divine Light", ImageId = 1468819804};
			{Name = "Death", ImageId = 2419083272};
			{Name = "Crash", ImageId = 1468820065};
			{Name = "Gravity", ImageId = 1468821559};
			}
		
		};
		-----------------------------------
		{
		Rarity = {Name = "Mythical",	Chance = 0.004, 	Color = Color3.fromRGB(170,0,225),	DuplicateReward = 0};
		Items = {
			
				{Name = "Time", ImageId = 2987584671};
				{Name = "Fire Dragon Slayer", ImageId = 2987584671};
				{Name = "Iron Dragon Slayer", ImageId = 2987584671};
				{Name = "Fire God Slayer", ImageId = 2987584671};
				{Name = "Sky Dragon Slayer", ImageId = 2987584671};
			}
		
		};
		-----------------------------------
		{
			Rarity = {Name = "Godly",	Chance = 0.001, 	Color = Color3.fromRGB(255, 255, 0),	DuplicateReward = 0};
			Items = {

				{Name = "Heaven's Angel", ImageId = 2987584671};
				{Name = "Death Angel", ImageId = 2987584671};
				{Name = "Fairy King", ImageId = 2987584671};
			}

		};
	};
	
	-- Records the group the item belongs to. This can be used to retreive data on the item's group (such as it's rarity, color, etc) when we only have info for the item.
	for groupIndex, group in pairs(itemTypes) do
		for i, item in pairs(group.Items) do
			item.GroupIndex = groupIndex
		end
	end
	
	return itemTypes
end

return contents

Yh you’re right , I think I know what to do now , well I could search a way for the script to halt until everything in the location is loaded.

well look, i know what u want to achieve and how to achieve it, but i cant seem to get to grips with ur code due to it being so large and we are kind of all over the place so ill just tell you how you want to achieve it

now that the script for putting magical abilitys into backpack works what you want to do is make that script wait for there to be a value in leader stats so this is how we achieve that.

put a Remote event into replicated storage and name it something like “LeaderStatEvent”

then when one of your scripts i dont know which one, puts one of the values into leader stats fire a ClientEvent to the client whom recieved the leaderstat and have the client event recieved in the script that we solved origionally should look something like this

this will not work because i gtg now but its something like this

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Elements = ReplicatedStorage:FindFirstChild("Elements")

local event = ReplicatedStorage.OnLeaderStatEvent --or whatever u are calling it

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local MagicFireSkills = Elements.Fire:GetChildren()
local MagicEarthSkills = Elements.Earth:GetChildren()
local MagicWindSkills = Elements.Wind:GetChildren()
local MagicLightningSkills = Elements.Lightning:GetChildren()
local MagicWaterSkills = Elements.Water:GetChildren()

event.fired:connect(function()
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		if Leaderstats.ObjectValue.Name == ("Fire") then
			MagicFireSkills:CLone().Parent = Player.Backpack
		elseif Leaderstats.ObjectValue.Name == ("Earth") then
			MagicEarthSkills:CLone().Parent = Player.Backpack
		elseif Leaderstats.ObjectValue.Name == ("Wind") then
			MagicWindSkills:CLone().Parent = Player.Backpack
		elseif Leaderstats.ObjectValue.Name == ("Lightning") then
			MagicLightningSkills:CLone().Parent = Player.Backpack
		elseif Leaderstats.ObjectValue.Name == ("Water") then
			MagicWaterSkills:CLone().Parent = Player.Backpack
		end
	end)
end)

this can be made more efficient but i gtg

and for more on events: click here

2 Likes