Hey.
I’m having a lot of troubles with this script. I’ve tried debugging it but I think I might need some help here.
The problem is that it plays only one animation from the table, but all the others are not playing. It also seems like when u equip the sword, the equip animation plays forever.
local script:
local tool = script.Parent
local remote = script:WaitForChild("Katana")
local enabled = false
tool.Equipped:Connect(function()
remote:FireServer("Equipped")
end)
tool.Unequipped:Connect(function()
remote:FireServer("Unequipped")
end)
tool.Activated:Connect(function()
if enabled == false then
enabled = true
remote:FireServer("Attack")
wait(0.7)
enabled = false
end
end)
script inside the local script:
local remote = script.Parent:WaitForChild("Katana")
remote.OnServerEvent:Connect(function(Player, Value)
local character = workspace:WaitForChild(Player.Name)
if Value == "Equipped" then
print("equipped")
local lookForAnimation = character:FindFirstChild("EquippedAnimation")
if lookForAnimation then
lookForAnimation:Destroy()
end
local animation = Instance.new("Animation", character)
animation.Name = "EquippedKatana"
animation.AnimationId = "rbxassetid://7425748912"
local loader = character:WaitForChild("Humanoid"):LoadAnimation(animation)
loader:Play()
elseif Value == "Unequipped" then
print("unequipped")
local lookForAnimation = character:FindFirstChild("EquippedAnimation")
if lookForAnimation then
local loader = character:WaitForChild("Humanoid"):LoadAnimation(lookForAnimation)
loader:Stop()
lookForAnimation:Destroy()
end
elseif Value == "Attack" then
print("Attack")
local availableAttackAnimations = {121254126, 121254126, 121254126}
local animation = Instance.new("Animation", character)
animation.Name = "AttackAnimation"
animation.AnimationId = "rbxassetid://"..tostring(availableAttackAnimations[math.random(3, #availableAttackAnimations)])
local loader = character:WaitForChild("Humanoid"):LoadAnimation(animation)
loader:Play()
local alreadyHitObjects = {}
script.Parent.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= Player.Name then
for _, alreadyHit in pairs(alreadyHitObjects)do
if alreadyHit == hit.Parent.Name then
return
end
end
alreadyHitObjects[#alreadyHitObjects + 1] = hit.Parent.Name
hit.Parent.Humanoid:TakeDamage(10)
end
end)
end
end)
Thanks in advance!