Tool only works when it starts out in backpack, not when moved into backpack

  1. What do you want to achieve?
    I want to be able to clone a tool from ServerStorage into a player’s backpack.

  2. What is the issue?
    The tool only works if it starts in the backpack, it doesn’t work when I move it into the backpack from a script. The tool appears and everything, but clicking doesn’t do anything and the animations don’t play.

  3. What solutions have you tried so far?
    I have tried disabling the scripts until they are in the backpack, but it doesn’t work. All the other solutions I have seen on the forums have not worked.

This is the tool hierarchy:
hierarchy

This is the server script in the tool:

local Players = game:GetService("Players")

local tool = script.Parent
local hitbox = tool.Hitbox
local stabEvent = tool.StabEvent

local function activated(player)
	
	if tool.Enabled then
		
		local char = player.Character or player.CharacterAdded:Wait()
		local hum = char:WaitForChild("Humanoid")
		
		tool.Enabled = false

		local hasFoundVictim = false

		wait(0.5)

		local hits = hitbox:GetTouchingParts()
		for _, part in pairs(hits) do

			if not hasFoundVictim then

				local hum = part.Parent:FindFirstChild("Humanoid")
				if hum then

					local victim = Players:GetPlayerFromCharacter(hum.Parent)

					if victim ~= player then

						print("Kill")
						victim.otherstats.Health.Value = 0
						hasFoundVictim = true

					end

				end

			end

		end

		wait(0.25)
		tool.Enabled = true
		
	end
	
end

stabEvent.OnServerEvent:Connect(activated)

Here is the local script in the tool:

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local char = player.CharacterAdded:Wait() or player.Character
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local tool = script.Parent
local stabEvent = tool:WaitForChild("StabEvent")
local idleAnim = tool:WaitForChild("IdleAnimation")

local idleTrack
local lastSlash = 1

-- When player attempts to stab
local function activated()
	
	stabEvent:FireServer()
	
	if lastSlash == 1 then lastSlash = 2 else lastSlash = 1 end
	
	local stabTrack = animator:LoadAnimation(tool:FindFirstChild("Stab" .. lastSlash .. "Animation"))
	stabTrack.Priority = Enum.AnimationPriority.Action2
	stabTrack:Play()
	
end


-- When tool is equipped
local function equipped()
	
	idleTrack = animator:LoadAnimation(idleAnim)
	idleTrack.Looped = true
	idleTrack.Priority = Enum.AnimationPriority.Action
	idleTrack:Play()
	
end


-- When tool is unequipped
local function unequipped()
	if idleTrack then
		
		idleTrack:Stop()
		idleTrack = nil
		
	end
end

tool.Activated:Connect(activated)
tool.Equipped:Connect(equipped)
tool.Unequipped:Connect(unequipped)

Any help is appreciated!

1 Like

When the script starts, there is no owner to generate a LocalPlayer. As part of the cloning process for the Tool, make sure all scripts are set to Disabled, then only Enable them once the Tool is parented into the players backpack.

As much as I want to say this is false, it is actually a true statement in some cases. I have gotten certain tools to work without using this method, but it appears Roblox now forces this method.

Anyways, you will need to do this solution.

I found out when I did this earlier I forgot to disable the local script. Thank you!