Localscript not functioning when tool is replicated

Whenever I pick up a tool and equip it which replicates it to the players backpack, the localscript inside of the tool doesn’t work whatsoever, it doesn’t even do a print. There are no errors being output…

The tool is being replicated through the server as well.

LocalScript:

 local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid

local PickaxeEquipAnim = script.Parent.PickaxeEquip
local MineAnim = script.Parent.Mine

local MineAnimation = Humanoid:LoadAnimation(MineAnim)
local PickaxeEquip = Humanoid:LoadAnimation(PickaxeEquipAnim)


local canSwing = true

local debounce = 0.8

script.Parent.Activated:Connect(function()
	
	print("Tool Hit")
		
end)



script.Parent.Equipped:Connect(function()
	print("Tool Equipped")

end)

image

ServerCode:

 if action == "Equip" and player.Inventory:FindFirstChild(item) and player.Inventory[item].Value > 0 then
		
		player.Inventory[item].Value -=1
		
		local newTool = game.ReplicatedStorage.Items[item]:Clone()
		newTool.Parent = player.Backpack
		local Humanoid = player.Character:FindFirstChildOfClass("Humanoid")
		Humanoid:EquipTool(newTool)

Edit: it now shows an error:

Im assuming because when I equip the item, the localscript can no longer find the animations. Anyway around this?

image

Could u show the Line 5 in Localscript

local PickaxeEquipAnim = script.Parent.PickaxeEquip

Try doing,
local PickaxeEquipAnim = script.Parent:WaitForChild("PickaxeEquip")
Glad it worked :happy3:

1 Like

For ur next Scripts dont forget to add :WaitForChild() because it takes Time to load all Objects

1 Like

Thanks, I should’ve known it was that simple of a solution :man_facepalming: thanks for the help :slightly_smiling_face:

1 Like