Issues With :Clone()

Hi, I am tryna make a tool that replaces your current tool/weapon into another and gives your old tool/weapon back.

(note: my system works using String Values so what ever the string value is, is the main weapon)


I am getting this error when using the tool

tool folder: (Its located inside ServerStorage)
image

I tried Printing the weapons name and playing around with print() and so far printing works its just Clone() that doesnt work

local Rep = game.ReplicatedStorage
local SerS = game.ServerStorage
local Weapons = SerS["Weapons/Armors"]
local EquippedWep = Rep.PlayerData

script.Parent.Activated:Connect(function(Character)
	--local WeaponName = Rep.PlayerData:FindFirstChild(Character.Name).Weapon.Value
	
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	local WeaponName = Rep.PlayerData[player.Name].PrimaryWeapon.Value
	local Weapon = game.ServerStorage["Weapons/Armors"]:FindFirstChild(WeaponName)
	
	local e = SerS["Weapons/Armors"]:FindFirstChild(WeaponName):Clone()
	print(e.Name)
	e.Parent = player:FindFirstChild("Backpack")
	
	if player then
		
		game.ReplicatedStorage.PlayerData[player.Name].PrimaryWeapon.Value = "LongSword"
		script.Parent:Destroy()
	end
end)

if you have any questions about the system let me know I might be able to answer

Change it to FindFirstChild(WeaponName, true) and that should fix it, The problem is you are looking in the Weapons/Armor folder not the Weapon folder that the weapons are in

like this?

local e = SerS["Weapons/Armors"].Weapon:FindFirstChild(WeaponName, true):Clone()
	print(e.Name)
	e.Parent = player:FindFirstChild("Backpack")

is this a localscript?

This text will be blurred

I am Deeply sorry for this Late response. and no this is normal script it isn’t local

Replace :FindFirstChild(WeaponName) to .Weapon, if it’s not working, do :WaitForChild("Weapon").

This is how your script should be:

local Rep = game.ReplicatedStorage
local SerS = game.ServerStorage
local Weapons = SerS["Weapons/Armors"]
local EquippedWep = Rep.PlayerData

script.Parent.Activated:Connect(function(Character)
	--local WeaponName = Rep.PlayerData:FindFirstChild(Character.Name).Weapon.Value
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	local WeaponName = Rep.PlayerData[player.Name].PrimaryWeapon.Value
	local Weapon = game.ServerStorage["Weapons/Armors"]:FindFirstChild(WeaponName)
	local e = SerS["Weapons/Armors"].Weapon
	e:Clone()
	print(e.Name)
	e.Parent = player:FindFirstChild("Backpack")
	
	if player then
		game.ReplicatedStorage.PlayerData[player.Name].PrimaryWeapon.Value = "LongSword"
		script.Parent:Destroy()
	end
end)

Yes, there’s some unlisted things about-in the script.
I think.

If it’s not working, consider doing :WaitForChild instead of .

local Rep = game.ReplicatedStorage
local SerS = game.ServerStorage
local Weapons = SerS["Weapons/Armors"]
local EquippedWep = Rep.PlayerData

script.Parent.Activated:Connect(function(Character)
	--local WeaponName = Rep.PlayerData:FindFirstChild(Character.Name).Weapon.Value
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	local WeaponName = Rep.PlayerData[player.Name].PrimaryWeapon.Value
	local Weapon = game.ServerStorage["Weapons/Armors"]:FindFirstChild(WeaponName)
	local e = SerS["Weapons/Armors"]:WaitForChild("Weapon")
	e:Clone()
	print(e.Name)
	e.Parent = player:FindFirstChild("Backpack")
	
	if player then
		game.ReplicatedStorage.PlayerData[player.Name].PrimaryWeapon.Value = "LongSword"
		script.Parent:Destroy()
	end
end)

I have no clue if that works cause when I inserted that script and Clicked/Activated the tool nothing happened, I inserted lots of prints and none of those prints got printed

(note: this tool doesn’t have a handle)

if there is something you need/must know about the tool or how its supposed to work feel free to ask me so maybe we can solve this issue quicker.

What is the Name of the tool? Your error basically says that FindFirstChild didn’t find it.

Then name one of the parent’s tool to Handle.

the system is bit hard to explain but in short:
Weapon tool is just 1 tool it changes stats/appearance based on PrimaryWeapon.Value (stringValue) this is located in Replicated Storage each player has his/her own PlayerData.

This tool I am trying to make already works, Only problem it does not give the weapon back after using it (I know I can remove the script.Parent:Destroy() part but I don’t want to)

issue is with this.

you’re trying to find the weapon name in the weapons/armors folder but theres a secondary folder inside weapons/armors you’re not accessing, which is the one with the actual weapon in.

local Weapon = game.ServerStorage["Weapons/Armors"].Weapon:FindFirstChild(WeaponName)

This Tool first Goes Tries to Find PlayersData then looks for PrimaryWeapon.Value. after the script finds it, it goes inside ServerStorage["Weapons/Armors"].Weapons then looks for primaryweapon value (in this folder the value/name is a tool) clones it (there is a tool variant of the weapon) and then it sets cloned tools parent to players backpack

but this script doesn’t work and that’s why I am here

local Rep = game.ReplicatedStorage
local SerS = game.ServerStorage
local Weapons = SerS["Weapons/Armors"]
local EquippedWep = Rep.PlayerData

script.Parent.Activated:Connect(function(Character)
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	local WeaponName = Rep.PlayerData[player.Name].PrimaryWeapon.Value
	local Weapon = game.ServerStorage["Weapons/Armors"].Weapon:FindFirstChild(WeaponName)

	local e = SerS["Weapons/Armors"]:FindFirstChild(WeaponName):Clone()
	print(e.Name)
	e.Parent = player:FindFirstChild("Backpack")

	if player then
		game.ReplicatedStorage.PlayerData[player.Name].PrimaryWeapon.Value = "LongSword"
		script.Parent:Destroy()
	end
end)

I got the same error

You need to change the second variable to access the folder too.

local e = SerS["Weapons/Armors"].Weapon:FindFirstChild(WeaponName):Clone()

still…

image

local Rep = game.ReplicatedStorage
local SerS = game.ServerStorage
local Weapons = SerS["Weapons/Armors"]
local EquippedWep = Rep.PlayerData

script.Parent.Activated:Connect(function(Character)
	--local WeaponName = Rep.PlayerData:FindFirstChild(Character.Name).Weapon.Value

	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	local WeaponName = Rep.PlayerData[player.Name].PrimaryWeapon.Value
	local Weapon = game.ServerStorage["Weapons/Armors"].Weapon:FindFirstChild(WeaponName)


	local e = SerS["Weapons/Armors"].Weapon:FindFirstChild(WeaponName):Clone()
	print(e.Name)
	e.Parent = player:FindFirstChild("Backpack")

	if player then

		game.ReplicatedStorage.PlayerData[player.Name].PrimaryWeapon.Value = "LongSword"
		script.Parent:Destroy()
	end
end)

I got it working

local Rep = game.ReplicatedStorage
local SerS = game.ServerStorage
local Weapons = SerS["Weapons/Armors"]
local EquippedWep = Rep.PlayerData

script.Parent.Activated:Connect(function(Character)
	--local WeaponName = Rep.PlayerData:FindFirstChild(Character.Name).Weapon.Value

	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	local WeaponName = Rep.PlayerData[player.Name].PrimaryWeapon
	local Weapon = game.ServerStorage["Weapons/Armors"].Weapon:FindFirstChild(WeaponName.Value)

	local e = SerS["Weapons/Armors"].Weapon:FindFirstChild(WeaponName.Value):Clone()
	print(e.Name)
	e.Parent = player:FindFirstChild("Backpack")

	if player then

		game.ReplicatedStorage.PlayerData[player.Name].PrimaryWeapon.Value = "LongSword"
		script.Parent:Destroy()
	end
end)

the issue was

local WeaponName = Rep.PlayerData[player.Name].PrimaryWeapon.Value 

I removed value part and wrote .Value next to every WeaponName inside the script
(If anybody knows how this worked please let me know)