Tool not functioning when cloned to backpack!

Hello everyone! So I’ve been trying to make a tool work, for some reason, when I put it inside StarterPack, It works, but if I put the tool in ServerStorage and then use a script to clone it into the players backpack, the tool appears, but doesnt function. Here are some screenshots.

Parented already in StarterPack - https://gyazo.com/9a92297b96a5dfc6bd69842cc29b2452
Parented using script -
https://gyazo.com/c02a4711369aa6952ee26448d68732d5

Code of the tool I’m using -


local tool = script.Parent
local player = game.Players.LocalPlayer
local rp = game:GetService("ReplicatedStorage")
local hum = player.CharacterAdded:Wait():WaitForChild("Humanoid")
local TweenService = game:GetService("TweenService")
local mouse = player:GetMouse()
local BarrageEvent = rp:WaitForChild("VampiricBarrage")
local holdingdown = false

local holdingdowncooldown =  0.7
--[[
tool.Activated:Connect(function()
	BarrageEvent:FireServer(tool)
end)
]]
function checkTool(character,toolName)
	 for _, v in pairs(character:GetChildren()) do 
        if v:IsA("Tool") then 
			if v.Name == toolName then
				return true
			end
        end
    end
	return false
end

mouse.Button1Down:Connect(function()

	if checkTool(player.Character,tool.Name) then
		holdingdown = true
		repeat 
			BarrageEvent:FireServer(tool)
			wait(holdingdowncooldown)
		until not holdingdown
	end
end)

mouse.Button1Up:Connect(function()
	if checkTool(player.Character,tool.Name) then
		holdingdown = false	
	end
end)

tool.Unequipped:Connect(function()
	holdingdown = false
end)

Code of the script that clones the tool into the player’s backpack -

local rp = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Shockwave = rp:WaitForChild("Shockwave")
local VampiricHealth = rp.Health
local VampiricBarrage = game:GetService("ServerStorage")["Vampiric Barrage"]
local shockwaveTween = TweenInfo.new(

	1,
	Enum.EasingStyle.Exponential,
	Enum.EasingDirection.In,
	0,
	false,
	0

)



local StartShockwave = {
Size = Vector3.new(20.919, 8.698, 25.416)
}

local EndShockwave = {

Size = Vector3.new(2.619, 1.089, 3.182);
	
}
local StoneMaskTransform = rp:WaitForChild("StoneMaskTransform")


StoneMaskTransform.OnServerEvent:Connect(function(player,tool)
	local ClonedShockWave = Shockwave:Clone()
	ClonedShockWave.Parent = workspace
	ClonedShockWave.Position = player.Character.HumanoidRootPart.Position
	
	TweenService:Create(ClonedShockWave,shockwaveTween,StartShockwave):Play()
	wait(1)
	TweenService:Create(ClonedShockWave,shockwaveTween,EndShockwave ):Play()
	wait(1)
	ClonedShockWave:Destroy()
	
	
	-- we give him vampire
	-- remove mask first
	player.Backpack:WaitForChild("Stone Mask"):Destroy()
	
	-- give him vampire abillities
	player.Character.Humanoid.MaxHealth = 150
	player.Character.Humanoid.Health = 150
	player.Character.Humanoid.WalkSpeed = 18
	-- give him vampiric face
	player.Character.Head.face.Texture = "rbxassetid://2606174048"
	
	-- give him vampiric healing 
	
	-- destroy old regen script
	player.Character.Health:Destroy()
	
	local ClonedVampiricHealth = VampiricHealth:Clone()
	ClonedVampiricHealth.Parent = player.Character
	ClonedVampiricHealth.Disabled = false
	
	local ClonedBarrage = VampiricBarrage:Clone()
	ClonedBarrage.Parent = player:WaitForChild("Backpack")
	ClonedBarrage.Enabled = true
	
	
end)
1 Like

Are you cloning it from a server or local script?

The tool script seems to be yielding at line 4:

local hum = player.CharacterAdded:Wait():WaitForChild("Humanoid")

It works when in StarterPlayer because the tool is put in Backpack when the character hasn’t been created yet. When you clone it using the script, the character is already created, so player.CharacterAdded:Wait() yields infinitely (this event only fires when a character is added, but if it already exists it will not fire).

First, you should not get the mouse at the beginning of the script and hook the events, because then the tool will fire on click even when you aren’t equipping it. Instead, put the on-click events inside a function that is connected to the tool’s Equipped event:

tool.Equipped:Connect(function(mouse)
--put on-click connections here
end)

Assuming the character is already created when the tool is given to them, you can get the Humanoid without using Player.CharacterAdded.

local hum = player.Character:WaitForChild("Humanoid")

EDIT: Your script doesn’t seem to use Humanoid anyways, so you could just remove this line. Unless you are going to add something that requires a reference to the Humanoid.

4 Likes

Thanks for the detailed soloution :slight_smile: