-
What do you want to achieve?
I want to be able to clone a tool from ServerStorage into a player’s backpack. -
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. -
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:
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!