Hello , i make a pickaxe animation ant it doesn"t work correctly , il play somtime and sometimes don’t play if anyone can help me …
robloxapp-20221226-1646119.wmv (1.9 MB)
Can we see a script? Do you want your animation to be looped when activated and then stop when deactivated? Or just play once the track ends then player have to activate again play?
local collect = game:GetService("CollectionService")
local num = 2 --Cooldown
local dmg = 10 --Damage
local tool = false
local punch = false
local Animating = false
script.Parent.Equipped:Connect(function()
local Animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Animation)
local humanoid = script.Parent.Parent.Humanoid
local StaticAnim = script.Static
local Static = script.Parent.Parent.Humanoid:LoadAnimation(StaticAnim)
local loadedAnimation = script.Parent.Parent:FindFirstChild("Humanoid"):LoadAnimation(StaticAnim)
loadedAnimation:Play()
script.Parent.Activated:Connect(function()
loadedAnimation:Stop()
end)
script.Parent.Deactivated:Connect(function()
loadedAnimation:Play()
end)
script.Parent.Unequipped:Connect(function()
loadedAnimation:Stop()
end)
script.Parent.Activated:connect(function()
if Animating == false then
Animating = true
local humanoid = script.Parent.Parent.Humanoid
local char = humanoid.Parent
local pick = script.Parent.Handle.Pick
local clone = script.Mined:Clone()
clone.Parent = char.Head
if tool == false then
tool = true
Animation:Play()
pick.Touched:connect(function(hit)
if punch == false then
if collect:HasTag(hit.Parent, "Ore") then
if hit.Parent.Rock.Health.Value > 0 then
char.Head.Mined:Play()
hit.Parent.Rock.Health.Value -= 1
end
end
punch = true
end
end)
wait(num)
tool = false
punch = false
wait(1.4)
Animation:Stop()
Animating = false
end
end
end)
end)
It looks like you have 2 different animations right? What does Static do and Animation do?
You repeated loading the StaticAnimation here:
local Static = script.Parent.Parent.Humanoid:LoadAnimation(StaticAnim)
local loadedAnimation = script.Parent.Parent:FindFirstChild("Humanoid"):LoadAnimation(StaticAnim)
If you remove the 2nd variable, instead of loadedAnimation:Play()
, just do Static:Play(), but you play it inside the Equipped, so once player equips it, it starts playing. You can remove that and just leave it in the Activated and Deactivated. If it doesn’t solve, I’ll try to replicate it in Studio.
Static is when then player is not mining , just to get pickaxe with 2 hands , and animation is for the pickaxing animation when the player is mining
Got it. One more question, is the script a LocalScript inside the tool or just a regular Script?
Is a regular script , and remouving the loadedanimation change anithing. The proble is with animation ,sometime play animation and some time no
Here’s what I did and it’s working on my end. I had to put the Activated, Deactivated, Unequipped, and Equipped all on their own threads. Since the Script is not a LocalScript, we can’t get the Humanoid from the LocalPlayer’s Character so we use functions and get the humanoid from each thread to play or stop animations.
local collect = game:GetService("CollectionService")
local num = 2 --Cooldown
local dmg = 10 --Damage
local tool = false
local punch = false
local Animating = false
local function StopAnimations(humanoid)
for _,track in humanoid.Animator:GetPlayingAnimationTracks() do
track:Stop()
end
end
local function playStatic(humanoid)
StopAnimations(humanoid)
task.wait()
local idling = humanoid.Animator:LoadAnimation(script.Static)
idling.Priority = Enum.AnimationPriority.Action
idling:Play()
end
local function playAnimation(humanoid)
StopAnimations(humanoid)
task.wait()
local mining = humanoid.Animator:LoadAnimation(script.Animation)
mining.Priority = Enum.AnimationPriority.Action
mining:Play()
end
script.Parent.Equipped:Connect(function()
local humanoid = script.Parent.Parent.Humanoid
StopAnimations(humanoid)
task.wait()
playStatic(humanoid)
end)
script.Parent.Activated:Connect(function() --Activated is when the left mouse button is pressed & hold
local humanoid = script.Parent.Parent.Humanoid
StopAnimations(humanoid)
if Animating == false then
Animating = true
local char = humanoid.Parent
local pick = script.Parent.Handle.Pick
local clone = script.Mined:Clone()
clone.Parent = char.Head
if tool == false then
tool = true
playAnimation(humanoid)
pick.Touched:Connect(function(hit)
if punch == false then
if collect:HasTag(hit.Parent, "Ore") then
if hit.Parent.Rock.Health.Value > 0 then
char.Head.Mined:Play()
hit.Parent.Rock.Health.Value -= 1
end
end
punch = true
end
end)
wait(num)
tool = false
punch = false
wait(1.4)
StopAnimations(humanoid)
Animating = false
end
end
end)
script.Parent.Deactivated:Connect(function() --Deactivated is when the left mouse button is released
local humanoid = script.Parent.Parent.Humanoid
StopAnimations(humanoid)
task.wait()
playStatic(humanoid)
end)
script.Parent.Unequipped:Connect(function()
local backpack = script.Parent.Parent
local player = backpack.Parent
local humanoid = player.Character.Humanoid
StopAnimations(humanoid)
end)
I know what’s the problem and i’ll help you once i get on my pc.
local player = game.Players.LocalPlayer
local character = workspace:FindFirstChild(player.Name)
local Humanoid = character:FindFirstChild("Humanoid")
local collect = game:GetService("CollectionService")
local num = 2 --Cooldown
local dmg = 10 --Damage
local tool = false
local punch = false
local Animating = false
script.Parent.Equipped:Connect(function()
local Animation = humanoid:LoadAnimation(script.Animation)
local StaticAnim = script.Static
local Static = humanoid:LoadAnimation(StaticAnim)
local loadedAnimation = humanoid:LoadAnimation(StaticAnim)
loadedAnimation:Play()
script.Parent.Activated:Connect(function()
loadedAnimation:Stop()
end)
script.Parent.Deactivated:Connect(function()
loadedAnimation:Play()
end)
script.Parent.Unequipped:Connect(function()
loadedAnimation:Stop()
end)
script.Parent.Activated:connect(function()
if Animating == false then
Animating = true
local pick = script.Parent.Handle.Pick
local clone = script.Mined:Clone()
clone.Parent = character.Head
if tool == false then
tool = true
Animation:Play()
pick.Touched:connect(function(hit)
if punch == false then
if collect:HasTag(hit.Parent, "Ore") then
if hit.Parent.Rock.Health.Value > 0 then
char.Head.Mined:Play()
hit.Parent.Rock.Health.Value -= 1
end
end
punch = true
end
end)
wait(num)
tool = false
punch = false
wait(1.4)
Animation:Stop()
Animating = false
end
end
end)
end)
Ok, so your problem might have been that your animation cannot get played because it cannot find the Humanoid, i think this is the solution.
Also turn your Script
into a LocalScript
one
local player = game.Players.LocalPlayer
local character = workspace:FindFirstChild(player.Name)
local Humanoid = character:FindFirstChildOfClass("Humanoid")
local collect = game:GetService("CollectionService")
local num = 2 --Cooldown
local dmg = 10 --Damage
local tool = false
local punch = false
local Animating = false
script.Parent.Equipped:Connect(function()
local Animation = humanoid:LoadAnimation(script.Animation)
local StaticAnim = script.Static
local Static = humanoid:LoadAnimation(StaticAnim)
local loadedAnimation = humanoid:LoadAnimation(StaticAnim)
loadedAnimation:Play()
script.Parent.Activated:Connect(function()
loadedAnimation:Stop()
end)
script.Parent.Deactivated:Connect(function()
loadedAnimation:Play()
end)
script.Parent.Unequipped:Connect(function()
loadedAnimation:Stop()
end)
script.Parent.Activated:connect(function()
if Animating == false then
Animating = true
local pick = script.Parent.Handle.Pick
local clone = script.Mined:Clone()
clone.Parent = character.Head
if tool == false then
tool = true
Animation:Play()
pick.Touched:connect(function(hit)
if punch == false then
if collect:HasTag(hit.Parent, "Ore") then
if hit.Parent.Rock.Health.Value > 0 then
char.Head.Mined:Play()
hit.Parent.Rock.Health.Value -= 1
end
end
punch = true
end
end)
wait(num)
tool = false
punch = false
wait(1.4)
Animation:Stop()
Animating = false
end
end
end)
end)
thanks , but is not resolve. I set the animation on loop mode and it reduce this bug a little bit. Thanks for yours helps.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.