How to add idle animation in the script - help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to add an idle animation in the script just like the swinging in the script

  2. What is the issue? Include screenshots / videos if possible!
    I tried to add an idle animation script by duplicating same as swinging
    but nothing work

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    No solution at all

local Players = game:GetService("Players") or game:FindService("Players")
local SoundService = game:GetService("SoundService") or game:FindService("SoundService")
local UserInputService = game:GetService("UserInputService") or game:FindService("UserInputService")

local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local AttemptInfect = Remotes:WaitForChild("AttemptInfect")
local SwooshSound = SoundService:WaitForChild("KnifeSwing")
local HitSound = SoundService:WaitForChild("KnifeHit")

local Handle = script.Parent:WaitForChild("Handle")
local SwingAnim = Handle:WaitForChild("Swing")

local ClickDebounce = false
local Character
local Humanoid
local ControllerAnim

script.Parent.Equipped:Connect(function()
	Character = Player.Character or Player.CharacterAdded:Wait()
	Humanoid = Character:WaitForChild("Humanoid")
	ControllerAnim = Humanoid:WaitForChild("Animator"):LoadAnimation(SwingAnim)
end)

script.Parent.Activated:Connect(function()
	if ClickDebounce then
		return
	end
	ClickDebounce = true
	
	ControllerAnim:Play()
	SwooshSound:Play()
	
	if Mouse.Target ~= nil and Character.PrimaryPart ~= nil then
		print(Mouse.Target)
		if Mouse.Target.Parent:FindFirstChild("Humanoid") ~= nil or Mouse.Target.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
			local TargetPlayer = Players:GetPlayerFromCharacter(Mouse.Target.Parent) or Players:GetPlayerFromCharacter(Mouse.Target.Parent.Parent)
			print(TargetPlayer)
			
			if TargetPlayer ~= nil and TargetPlayer.Character.PrimaryPart ~= nil then
				print("Player detected!")
				
				local player1Direction = Character.PrimaryPart.CFrame.LookVector
				local player2Position = TargetPlayer.Character:WaitForChild("HumanoidRootPart").Position
				local player1ToPlayer2 = (player2Position - Player.Character.PrimaryPart.Position).Unit
				
				print(player1Direction:Dot(player1ToPlayer2))
				
				if (TargetPlayer.Character.PrimaryPart.Position - Character.PrimaryPart.Position).Magnitude <= 3 and player1Direction:Dot(player1ToPlayer2) > 0.5 then
					print("Close enough")
					local Result = AttemptInfect:InvokeServer(TargetPlayer)
					if Result ~= nil then
						if Result == "Cooldown" then
							print("Cooldown is active")
						elseif Result == "Infected" then
							HitSound:Play()
						end
					end
				else
					print("Not close")
				end
			end
		end
	end
	
	task.wait(1)
	ClickDebounce = false
end)

here how the tool look like and the inside
image

Dont worry people I asked the ai assistant
and it work

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