Tools not being cloned into players backpack after death

I have an inventory in which players can equip and unequip guns. After the player dies he cant equip a gun anymore. Help would be very appreciated.

videos, screenshots and your code would be very nice

1 Like

Hey, could I add you to the game it would be easier and for some reason i couldnt make a video of it.

Im a little to busy for that sorry,

Okay so this is the code of the tool removing and adding:

local toolManagerVal = game:GetService("ReplicatedStorage"):WaitForChild("Values"):WaitForChild("toolManagerVal")

local plr = game.Players.LocalPlayer

local RS = game:GetService("ReplicatedStorage")

local InvGui = plr.PlayerGui:WaitForChild("InventoryGui")
local Custom = plr.PlayerGui:WaitForChild("CustomGUI")
local ammo = plr.PlayerGui:WaitForChild("ammo")

if not plr.Character then
	plr.CharacterAppearanceLoaded:Wait()
end

if toolManagerVal.Value == "build" then
	for i, ammoGui in ammo:GetChildren() do
		if  ammoGui:IsA("ScreenGui") then
			if ammoGui.Enabled == true then
				ammoGui.Enabled = false
			end
		end
	end
	InvGui.Enabled = false
	local back = false
	local starter = false
	local char = false
	if plr.Character then
		local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
		if hum then
			hum:UnequipTools()
		end
	end
	task.wait(0.4)
	for i, v in plr.Backpack:GetChildren() do
		if v:FindFirstChild("ammo") then 
			v:Destroy()
		end
	end
	for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
		if v:FindFirstChild("ammo") then 
			v:Destroy()
		end
	end
	for i, v in plr.Backpack:GetChildren() do
		if v:FindFirstChild("BuildVal") then 
			back=true
		end
	end
	for i, v in plr.Character:GetChildren() do
		if v:FindFirstChild("BuildVal") then 
			char=true
		end
	end
	for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
		if v:FindFirstChild("BuildVal") then 
			starter=true
		end
	end
	if back == false and char == false then
		RS.starterTools.Build:Clone().Parent = plr.Backpack
	end
	if starter == false then
		RS.starterTools.Build:Clone().Parent = plr:FindFirstChildWhichIsA("StarterGear")
	end
	
	print("Build Tool has been cloned into the players backpack")
		
	
elseif toolManagerVal.Value == "weapons" then
	Custom.Enabled = false
	InvGui.Enabled = true
	if plr.Character then
		local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
		if hum then
			hum:UnequipTools()
		end
	end
	task.wait(1)task.wait(0.4)for i, v in plr.Backpack:GetChildren() do
		if v:FindFirstChild("BuildVal") then 
			v:Destroy()
		end
	end
	for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
		if v:FindFirstChild("BuildVal") then 
			v:Destroy()
		end
	end
end

toolManagerVal.Changed:Connect(function(val)
	if toolManagerVal.Value == "build" then
		InvGui.Enabled = false
		local back = false
		local starter = false
		local char = false
		if plr.Character then
			local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
			if hum then
				hum:UnequipTools()
			end
		end
		task.wait(0.4)
		for i, v in plr.Backpack:GetChildren() do
			if v:FindFirstChild("ammo") then 
				v:Destroy()
			end
		end
		for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
			if v:FindFirstChild("ammo") then 
				v:Destroy()
			end
		end
		for i, v in plr.Backpack:GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				back=true
			end
		end
		for i, v in plr.Character:GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				char=true
			end
		end
		for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				starter=true
			end
		end
		
		if back == false and char == false then
			RS.starterTools.Build:Clone().Parent = plr.Backpack
		end
		if starter == false then
			RS.starterTools.Build:Clone().Parent = plr:FindFirstChildWhichIsA("StarterGear")
		end

		print("Build Tool has been cloned into the players backpack")


	elseif toolManagerVal.Value == "weapons" then
		InvGui.Enabled = true
		if plr.Character then
			local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
			if hum then
				hum:UnequipTools()
			end
		end
		task.wait(0.4)
		for i, v in plr.Backpack:GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				v:Destroy()
			end
		end
		for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				v:Destroy()
			end
		end
	end
end)

plr.CharacterAdded:Connect(function()
	if toolManagerVal.Value == "build" then
		for i, ammoGui in ammo:GetChildren() do
			if  ammoGui:IsA("ScreenGui") then
				if ammoGui.Enabled == true then
					ammoGui.Enabled = false
				end
			end
		end
		InvGui.Enabled = false
		local back = false
		local starter = false
		local char = false
		if plr.Character then
			local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
			if hum then
				hum:UnequipTools()
			end
		end
		task.wait(0.4)
		for i, v in plr.Backpack:GetChildren() do
			if v:FindFirstChild("ammo") then 
				v:Destroy()
			end
		end
		for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
			if v:FindFirstChild("ammo") then 
				v:Destroy()
			end
		end
		for i, v in plr.Backpack:GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				back=true
			end
		end
		for i, v in plr.Character:GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				char=true
			end
		end
		for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				starter=true
			end
		end
		if back == false and char == false then
			RS.starterTools.Build:Clone().Parent = plr.Backpack
		end
		if starter == false then
			RS.starterTools.Build:Clone().Parent = plr:FindFirstChildWhichIsA("StarterGear")
		end

		print("Build Tool has been cloned into the players backpack")


	elseif toolManagerVal.Value == "weapons" then
		Custom.Enabled = false
		InvGui.Enabled = true
		if plr.Character then
			local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
			if hum then
				hum:UnequipTools()
			end
		end
		task.wait(1)task.wait(0.4)for i, v in plr.Backpack:GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				v:Destroy()
			end
		end
		for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
			if v:FindFirstChild("BuildVal") then 
				v:Destroy()
			end
		end
	end

	toolManagerVal.Changed:Connect(function(val)
		if toolManagerVal.Value == "build" then
			InvGui.Enabled = false
			local back = false
			local starter = false
			local char = false
			if plr.Character then
				local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
				if hum then
					hum:UnequipTools()
				end
			end
			task.wait(0.4)
			for i, v in plr.Backpack:GetChildren() do
				if v:FindFirstChild("ammo") then 
					v:Destroy()
				end
			end
			for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
				if v:FindFirstChild("ammo") then 
					v:Destroy()
				end
			end
			for i, v in plr.Backpack:GetChildren() do
				if v:FindFirstChild("BuildVal") then 
					back=true
				end
			end
			for i, v in plr.Character:GetChildren() do
				if v:FindFirstChild("BuildVal") then 
					char=true
				end
			end
			for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
				if v:FindFirstChild("BuildVal") then 
					starter=true
				end
			end

			if back == false and char == false then
				RS.starterTools.Build:Clone().Parent = plr.Backpack
			end
			if starter == false then
				RS.starterTools.Build:Clone().Parent = plr:FindFirstChildWhichIsA("StarterGear")
			end

			print("Build Tool has been cloned into the players backpack")


		elseif toolManagerVal.Value == "weapons" then
			InvGui.Enabled = true
			if plr.Character then
				local hum = plr.Character:FindFirstChildWhichIsA("Humanoid")
				if hum then
					hum:UnequipTools()
				end
			end
			task.wait(0.4)
			for i, v in plr.Backpack:GetChildren() do
				if v:FindFirstChild("BuildVal") then 
					v:Destroy()
				end
			end
			for i, v in plr:WaitForChild("StarterGear"):GetChildren() do
				if v:FindFirstChild("BuildVal") then 
					v:Destroy()
				end
			end
		end
	end)
end)

well you shouldnt be outting items into the player via the client. Do it via the server. This will probably help resolve some of you’re problems.
Correct me if this isnt just a local script lol

This is a local script tho how should I remove or add tools to the play via a server script?

You’d do it the exact way you are doing it now you’d just need to make some small changes

1 Like