So I have this script for a melee weapon. It works fine until you die. That's when the script completely breaks. This is a localscript and the remote event isn't even fired whenever this happens.
This is the error I've been getting from this: Animations is not a valid member of Tool
Here's the script [local script]:
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent
local cooldown = .35
local slashPick = math.random(1,2)
local isActive = false
local canDamage = false
local animationList = {
Animation_1 = humanoid:LoadAnimation(tool.Animations:WaitForChild("Slash1")),
Animation_2 = humanoid:LoadAnimation(tool.Animations:WaitForChild("Slash2")),
}
local function onActivate()
if isActive == false then
isActive = true
canDamage = true
local slashAnimation = animationList["Animation_"..slashPick]
slashAnimation:Play()
slashPick = math.random(1,2)
wait(cooldown)
canDamage = false
isActive = false
end
end
local function onTouched(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and canDamage then
if humanoid.Health > 0 then
canDamage = false
replicatedStorage.DamageEvent:FireServer(hit, humanoid, slashPick)
end
end
end
tool.Activated:Connect(onActivate)
tool.Hitbox.Touched:Connect(onTouched)
