I am making a melee system and for that I made animations but the animations sometimes play and sometimes don’t at all which is very frusturating.
local Scripts = script.Parent
local Folder = Scripts.Parent
local Tool = Folder.Parent
local Melee = Tool.Melee
local M6D = Instance.new("Motor6D")
local Anim
Tool:GetPropertyChangedSignal("Parent"):Connect(function()
local Character = Tool.Parent
if Character:FindFirstChild("Humanoid") then
Anim = Character.Humanoid.Animator:LoadAnimation(script.Hold)
Anim.Priority = Enum.AnimationPriority.Idle
Anim:Play(0,1,1)
M6D.Part0 = Character:FindFirstChild("Right Arm")
M6D.Part1 = Melee.Handle
M6D.Parent = Character:FindFirstChild("Right Arm")
Melee.Parent = Character
else
if Anim.IsPlaying then
Anim:Stop(0)
end
M6D.Parent = nil
M6D.Part0 = nil
M6D.Part1 = nil
Melee.Parent = Tool
end
end)
local db = false
local lastpos = Melee.PrimaryPart.Position
local db2 = false
Scripts.Click.OnServerEvent:Connect(function(plr)
if not db then
db = true
local Character = Tool.Parent
local HRP = Character.HumanoidRootPart
local Hit = Character.Humanoid.Animator:LoadAnimation(script.Hit)
Hit.Priority = Enum.AnimationPriority.Action
Hit.Looped = false
Hit:Play(0,1,1)
lastpos = Melee.Handle.Position
local op = OverlapParams.new()
op.FilterDescendantsInstances = {Character}
local hitzombies = {}
repeat
for i,v in pairs(workspace:GetPartsInPart(Melee.Handle,op)) do
local h = v.Parent:FindFirstChild("Humanoid")
if h then
if not table.find(hitzombies,h) then
if v:FindFirstChild("Health") then
v.Health.Value -= Folder.Config.Damage.Value
else
h:TakeDamage(Folder.Config.Damage.Value)
end
h.HealthChanged:Connect(function()
if h.Health <= 0 then
if not db2 then
db2 = true
if v.Name == "Head" then
-- something was here but i removed it
else
-- something was here but i removed it
end
wait(0.5)
db2 = false
end
end
end)
h.PlatformStand = true
h.RootPart.Velocity = (h.RootPart.Position - HRP.Position).Unit * Folder.Config.Knockback.Value
coroutine.resume(coroutine.create(function()
wait(Folder.Config.Stun.Value)
h.PlatformStand = false
end))
table.insert(hitzombies,h)
end
end
end
wait()
until not Hit.IsPlaying
db = false
end
end)
Why are you doing Tool:GetPropertyChangedSignal(“Parent”)? There are hooks to detect if a tool is equipped. I’ve modified your script to reflect that.
local Scripts = script.Parent
local Folder = Scripts.Parent
local Tool = Folder.Parent
local Melee = Tool.Melee
local M6D = Instance.new("Motor6D")
local Anim
Tool.Equipped:Connect(function()
local Character = Tool.Parent
local Humanoid = Character:WaitForChild("Humanoid", 5)
local RightArm = Character:WaitForChild("Right Arm", 5)
if not Humanoid or not RightArm then
return
end
Anim = Humanoid.Animator:LoadAnimation(script.Hold)
Anim.Priority = Enum.AnimationPriority.Idle
Anim:Play(0,1,1)
M6D.Part0 = RightArm
M6D.Part1 = Melee.Handle
M6D.Parent = RightArm
Melee.Parent = Character
end)
Tool.Unequipped:Connect(function()
if Anim.IsPlaying then
Anim:Stop(0)
end
M6D.Parent = nil
M6D.Part0 = nil
M6D.Part1 = nil
Melee.Parent = Tool
end)
local db = false
local lastpos = Melee.PrimaryPart.Position
local db2 = false
Scripts.Click.OnServerEvent:Connect(function(plr)
if not db then
db = true
local Character = Tool.Parent
local HRP = Character.HumanoidRootPart
local Hit = Character.Humanoid.Animator:LoadAnimation(script.Hit)
Hit.Priority = Enum.AnimationPriority.Action
Hit.Looped = false
Hit:Play(0,1,1)
lastpos = Melee.Handle.Position
local op = OverlapParams.new()
op.FilterDescendantsInstances = {Character}
local hitzombies = {}
repeat
for i,v in pairs(workspace:GetPartsInPart(Melee.Handle,op)) do
local h = v.Parent:FindFirstChild("Humanoid")
if h then
if not table.find(hitzombies,h) then
if v:FindFirstChild("Health") then
v.Health.Value -= Folder.Config.Damage.Value
else
h:TakeDamage(Folder.Config.Damage.Value)
end
h.HealthChanged:Connect(function()
if h.Health <= 0 then
if not db2 then
db2 = true
if v.Name == "Head" then
-- something was here but i removed it
else
-- something was here but i removed it
end
wait(0.5)
db2 = false
end
end
end)
h.PlatformStand = true
h.RootPart.Velocity = (h.RootPart.Position - HRP.Position).Unit * Folder.Config.Knockback.Value
coroutine.resume(coroutine.create(function()
wait(Folder.Config.Stun.Value)
h.PlatformStand = false
end))
table.insert(hitzombies,h)
end
end
end
wait()
until not Hit.IsPlaying
db = false
end
end)
My question is not about how i write my scripts its about WHY animation isnt working.
local Scripts = script.Parent
local Folder = Scripts.Parent
local Tool = Folder.Parent
local re = game.ReplicatedStorage.Dialog
local db = false
local kills = {
"Nice kill!",
"Good kill, kid",
"Perfect execution.",
"You just chopped him up, kid!",
"A few more."
}
local db2 = false
Tool.Equipped:Connect(function()
local Character = Tool.Parent
Anim = Character.Humanoid.Animator:LoadAnimation(script.Hold)
Anim.Priority = Enum.AnimationPriority.Action
Anim.Looped = true
Anim:Play(0,1,1)
end)
Tool.Unequipped:Connect(function()
if Anim.IsPlaying then
Anim:Stop()
end
end)
local function hit()
if not db then
db = true
local Character = Tool.Parent
local HRP = Character.HumanoidRootPart
local Anim = Character.Humanoid.Animator:LoadAnimation(script.Hit)
Anim.Priority = Enum.AnimationPriority.Action4
Anim.Looped = false
Anim:Play(0,1,1)
local op = OverlapParams.new()
op.FilterDescendantsInstances = {Character}
local hitzombies = {}
repeat
for i,v in pairs(workspace:GetPartsInPart(Tool.Hitbox,op)) do
local h = v.Parent:FindFirstChild("Humanoid")
print(v)
if h then
if not table.find(hitzombies,h) then
local critical = (math.random(Folder.Config.Critical.Value,10) == 10 and 2 or 1)
if v:FindFirstChild("Health") then
v.Health.Value -= Folder.Config.Damage.Value*critical
else
h:TakeDamage(Folder.Config.Damage.Value*critical)
end
h.HealthChanged:Connect(function()
if h.Health <= 0 then
if not db2 then
db2 = true
if v.Name == "Head" then
re:FireAllClients("Commander","You just chopped someones head off, kid!")
else
re:FireAllClients("Commander",kills[math.random(1,#kills)])
end
wait(0.5)
db2 = false
end
end
end)
h.PlatformStand = true
h.RootPart.Velocity = (h.RootPart.Position - HRP.Position).Unit * Folder.Config.Knockback.Value
coroutine.resume(coroutine.create(function()
wait(Folder.Config.Stun.Value)
h.PlatformStand = false
end))
table.insert(hitzombies,h)
end
end
end
wait()
until not Anim.IsPlaying
db = false
end
end
Tool.Activated:Connect(hit)
Sure but one thing is that SOMETIMES it works and SOMETIMES it doesnt’t (I use caps like bold text ok? I am not mad). Like there is a 80% chance it works and 20% it won’t. Maybe its just loading issues?
IF your wondering that I didn’t state this in the Original Post then
I too can not think of anything that can be interfering. Maybe its my connection issues? Maybe the animation didn’t load properly? I think its my connection issues but can’t be so sure thats why this post exists.
WOW OKAY I fixed it. The problem was that the repeat loop was not stopping and kept continuing which caused the db to stay true preventing further things from happening.
Heres what I did btw if your interested: (tick()-st) >= Folder.Config.Wait.Value
And thank YOU for being the only person who atleast tryed to help me. But hey! Its the thought that counts!