My Code (client-sided)

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer

local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")


local CombatEnabled = false

local CombatAnim = script:WaitForChild("CombatAnim")

local animTable = {"rbxassetid://5021409784";"rbxassetid://5021418974";"rbxassetid://5021422938";"rbxassetid://5021425832"}
				
local debounce = false

UserInputService.InputBegan:Connect(function(Input,IsTyping)
	if not IsTyping then
		if Input.KeyCode == Enum.KeyCode.E and debounce == false then
			print("Combat Enabled!")
			CombatEnabled = true
			
			
			spawn(function()
				local AnimCount = nil
				
				while CombatEnabled == true do
					local randomAnimation = math.random(1, #animTable)
					local randomAnim_Value = animTable[randomAnimation]
					
					      CombatAnim.AnimationId = tostring(randomAnim_Value)
					      local CombatAnimLoader = Humanoid:LoadAnimation(CombatAnim)
					     CombatAnimLoader.Priority = Enum.AnimationPriority.Action
					
					    if AnimCount ~= CombatAnim.AnimationId then
						       CombatAnimLoader:Play()
						        print(randomAnimation)
						
						game.ReplicatedStorage.Combat:FireServer()
						
						         wait(CombatAnimLoader.Length + 0.25)
						         AnimCount = CombatAnim.AnimationId
						
					             if CombatEnabled == false then
						                     print("Combat Disabled!")
						                         break
					                      end
				                   end
		                    end
		             end)
	          end
       end
end)



UserInputService.InputEnded:Connect(function(Input, IsTyping)
	if not IsTyping then
		if Input.KeyCode == Enum.KeyCode.E and debounce == false then
			CombatEnabled = false
			
             spawn(function()			
			      debounce = true
			           wait(0.5)
			             debounce = false
			       end)
		     end
	   end
end)

this is what happens: https://gyazo.com/659a606e84fa610ec8298c3dcc26e397

2 comments

0

It must be because of the spawn function spawns arent that great at waiting for data to be retrieved instead use coroutine.wrap

0

Ill try this thanks