Animation plays Twice

Hey, I have an issue, my script below works perfectly fine functionally but there’s a big issues, for some reason the animation bugs out and plays 2-3 times, its very glitchy, and I have no idea why…

Here is my script,

script.Parent.OnServerEvent:Connect(function(plr,direction,mouseaim)
	local OnHit = false
	local Alive = true
	local Damage = 20
	local hrp = plr.Character:WaitForChild("HumanoidRootPart")
	local RS = game:GetService("ReplicatedStorage")

	-- FOLDERS --
	local Remotes = RS.Remotes
	local Tween = game:GetService("TweenService")
	local Replicate = Remotes.Replicate
	local Remotes2 = RS:WaitForChild("Events"):WaitForChild("Remotes")
	local HitCounterRemotes = Remotes2:WaitForChild("HitCounter")
	local Hits = {}
	local Modules = game.ReplicatedStorage.Modules
	local misc = require(Modules.Misc)
	local CS = game:GetService("CollectionService")
	local tag = "Ragdoll" 
	local AirImmunityTag = "AirDown"
	local M1ImmunityTag = "Immunity"
	local flh = game.ReplicatedStorage.Hitboxes.hbox3:Clone()
	flh.Parent = workspace.Debris
	flh.CFrame = hrp.CFrame *CFrame.new(0,-2,0)
	local Sound2 = script:WaitForChild("Hit")
	local ia =	plr.Character:FindFirstChild("IsAttacking")
	spawn(function()
		ia.Value = true
		wait(1)
		ia.Value = false
	end)
	local TS = game:GetService("TweenService")
	
	local debounce = false
	
	flh.Touched:Connect(function(hit, Player)
		if debounce then return end
		debounce = true
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
			if not hit.Parent.Humanoid:FindFirstChild(plr.Name) then
				if Hits[hit.Parent.Name] then
					return
				end
				local charh = hit.Parent

				local bt = hit.Parent:WaitForChild("BlockTime")
				local eHum = hit.Parent.Humanoid
				
				eHum.Parent.HumanoidRootPart.Orientation = plr.Character.HumanoidRootPart.Orientation - Vector3.new(0, 180, 0)
				eHum.Parent.HumanoidRootPart.Position = Vector3.new(plr.Character.HumanoidRootPart.Position.X, plr.Character.HumanoidRootPart.Position.Y, plr.Character.HumanoidRootPart.Position.Z - 4)
				
				eHum.WalkSpeed = 0
				CS:AddTag(eHum.Parent, M1ImmunityTag)
				CS:AddTag(plr.Character.Humanoid.Parent, M1ImmunityTag)
			
				local anim = eHum:LoadAnimation(script.Parent.Parent.SkullCrusherOpposition)
				anim:Play()
				anim.Stopped:Wait()
				
				CS:RemoveTag(charh, M1ImmunityTag)
				CS:RemoveTag(plr.Character.Humanoid.Parent, M1ImmunityTag)
				
				CS:AddTag(charh, AirImmunityTag)
				
				debounce = false

			end
		end

	end)
	wait(3)
	flh:Destroy()

	wait(5)


end)

If anyone could help it would mean so much!

1 Like

Can you share the code that calls OnServerEvent?

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
Mouse = plr:GetMouse()
local Debounce = 1
local Tool = script.Parent
local char = plr.CharacterAdded:Wait()
local equipped2 = false
local Equipped = script.Parent:WaitForChild("Equipped")
local isA = char:FindFirstChild("IsAttacking")
Tool.Equipped:Connect(function()
	
	equipped2 = true


end)

Tool.Unequipped:Connect(function()
	
	equipped2 = false


end)

UIS.InputBegan:Connect(function(Input,isTyping)
	if Input.KeyCode == Enum.KeyCode.G and Debounce == 1 then
		if isTyping then return end
		if isA == true then return end
		if equipped2 == false then return end
		if Player.Character:FindFirstChild("isBlocking").Value == true then return end
		if Player.Character:FindFirstChild("IsAttacking").Value == true then return end
		if Player.Character:FindFirstChild("IsJumping").Value == true then return end
if Player.Character:FindFirstChild("Ragdoll") then return end
		if Player.Character:FindFirstChild("PBSTUN") then return end	
		if Player.Character:FindFirstChild("noJump") then return end

		
		Debounce = 2

		local mousepos = Mouse.Hit
		
			plr.Character.HumanoidRootPart.Anchored = false
		local Track2 = plr.Character.Humanoid:LoadAnimation(script.SkullCrusherUser)
		Track2:Play()
		
		plr.Character.Humanoid.WalkSpeed = 0
		script.RemoteEvent:FireServer(mousepos,Mouse.Hit.p)
		wait(2)
		script.RemoteEvent.SkullCrusher.Swing:Play()
		script.RemoteEvent.SkullCrusher.Swing.Stopped:Wait()
		plr.Character.Humanoid.WalkSpeed = 15
		wait(30) --COOLDOWN
		Debounce = 1
		end
end)

The animation is playing twice because you are calling it twice.

local anim = eHum:LoadAnimation(script.Parent.Parent.SkullCrusherOpposition)
anim:Play()
anim.Stopped:Wait()

You are loading the animation, playing it, and then waiting for it to stop. Then, you are playing it again.

local anim = eHum:LoadAnimation(script.Parent.Parent.SkullCrusherOpposition)
anim:Play()
anim.Stopped:Wait()
anim:Play()

To fix this, you should just remove the second play.

local anim = eHum:LoadAnimation(script.Parent.Parent.SkullCrusherOpposition)
anim:Play()
anim.Stopped:Wait()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.