Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local AxeTool = script.Parent
- local treeChopRequestRemote = game.ReplicatedStorage:WaitForChild("TreeChopRequest")
- local localPalyer = game.Players.LocalPlayer
- local damagePart = AxeTool:FindFirstChild("DamagePart")
- local slashSound = AxeTool:FindFirstChild("SlashSound")
- local AxeAnimation = AxeTool:FindFirstChild("AnimAxe")
- local isAnimationPlaying = false
- local animationTrack , animationStoppedConnection
- local ANIMATION_DELAY = 0.5
- local function resetAnimationState()
- isAnimationPlaying = false
- if animationStoppedConnection then
- animationStoppedConnection:Disconnect()
- animationStoppedConnection = nil
- end
- if animationTrack then
- animationTrack:Stop()
- animationTrack = nil
- end
- end
- local function playChopAnimation()
- if isAnimationPlaying then return end
- local character = localPalyer.Character or localPalyer.CharacterAdded:Wait()
- local humaiond = character:FindFirstChildOfClass("Humanoid")
- if not humaiond then return end
- if AxeAnimation then
- animationTrack = humaiond:LoadAnimation(AxeAnimation)
- isAnimationPlaying = true
- animationTrack:Play()
- if slashSound then
- slashSound:Play()
- end
- treeChopRequestRemote:FireServer(damagePart)
- animationStoppedConnection = animationTrack.Stopped:Connect(function()
- task.wait(ANIMATION_DELAY)
- resetAnimationState()
- end)
- else
- treeChopRequestRemote:FireServer(damagePart)
- if slashSound then
- slashSound:Play()
- end
- end
- end
- if AxeTool:IsA("Tool") then
- AxeTool.Activated:Connect(playChopAnimation)
- AxeTool.Unequipped:Connect(resetAnimationState)
- end
Advertisement
Add Comment
Please, Sign In to add comment