When I try to clone in the variable "Sword" it gives me an error: attempt to index nil with clone, but when I try to clone the other tools it works. Here is the code:

local RE = game:GetService("ReplicatedStorage").RemoteEventTL

game.Players.PlayerAdded:Connect(function(plr)
	repeat wait() until plr.Team == game:GetService("Teams").Swordsmen or plr.Team == game:GetService("Teams"):FindFirstChild("Chi-Fighters")
	local EquipSword = plr:FindFirstChild("EquipSword").Value
	if plr.Team == game:GetService("Teams").Swordsmen then
		if EquipSword.Value ~= "None" then
			local DmgSword =  game:GetService("ReplicatedStorage").Swords:FindFirstChild(EquipSword):Clone()
			DmgSword.Parent = plr.Backpack
		else
			local Sword = game:GetService("ReplicatedStorage"):FindFirstChild("TrainingSword"):Clone()
			Sword.Parent = plr.Backpack
		end
	end
	
	if plr.Team == game:GetService("Teams"):FindFirstChild("Chi-Fighters") then
		local Weight = game:GetService("ReplicatedStorage").Weight:Clone()
		Weight.Parent = plr.Backpack
	end
end)

RE.OnServerEvent:Connect(function(plr)
	local EquipSword = plr:FindFirstChild("EquipSword").Value
	if plr.Team == game:GetService("Teams").Swordsmen then
		if EquipSword.Value ~= "None" then
			local DmgSword =  game:GetService("ReplicatedStorage").Swords:FindFirstChild(EquipSword):Clone()
			DmgSword.Parent = plr.Backpack
		else
			local Sword = game:GetService("ReplicatedStorage"):FindFirstChild("TrainingSword"):Clone()
			Sword.Parent = plr.Backpack
		end
	end

	if plr.Team == game:GetService("Teams"):FindFirstChild("Chi-Fighters") then
		local Weight = game:GetService("ReplicatedStorage").Weight:Clone()
		Weight.Parent = plr.Backpack
	end
end)

2 comments

0

That is because there is no 'EquipSword' in your sword. That's why :FindFirstChild() is returning 'nil'.

0

DmgSword works but Sword doesnt