Help with a flashlight script

I’m trying to make a phone flashlight script with animations right now, but every time I use it the animations play and there’s no errors yet the looped animation for the holding of the phone always stops despite it being looped in the animation. I’ve tried to change the code and the animation but it doesn’t seem to work. I tried to stop all the animations before starting the loop but that doesn’t work as well. Am I doing something wrong?

local uis = game:GetService("UserInputService")

local flashlight = false
local cooldown = false

local char = script.Parent
local root = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")

local takeOut = animator:LoadAnimation(script:WaitForChild("TakeOut"))
takeOut.Priority = Enum.AnimationPriority.Action2
takeOut.Looped = false

local loop = animator:LoadAnimation(script:WaitForChild("FlashlightLoop"))
loop.Priority = Enum.AnimationPriority.Action
loop.Looped = true

local putAway = animator:LoadAnimation(script:WaitForChild("PutAway"))
loop.Priority = Enum.AnimationPriority.Action2
loop.Looped = false

uis.InputBegan:Connect(function(input, gameEvent)
	if gameEvent then return end
	
	wait()
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.F then
			if not flashlight and not cooldown then
				local phone = script.PhoneHandle:Clone()
				phone.Parent = workspace
				
				local motor6d = script.HandleMotor6D:Clone()
				motor6d.Parent = char:WaitForChild("Right Arm")
				motor6d.Part0 = char:WaitForChild("Right Arm")
				motor6d.Part1 = phone
				
				takeOut:Play()
				
				takeOut.Stopped:Wait()
				
				for i,v in pairs(animator:GetPlayingAnimationTracks()) do
					v:Stop()
				end
				
				wait()
				
				loop:Play()
				
				wait()
				
				cooldown = true
				wait()
				flashlight = true
				wait(2)
				cooldown = false
			elseif flashlight and not cooldown then
				for i,v in pairs(animator:GetPlayingAnimationTracks()) do
					v:Stop()
				end
				wait()
				cooldown = true
				local phone = workspace:WaitForChild("PhoneHandle")
				phone.LightAttach.SpotLight.Enabled = false
				wait(0.2)
				putAway:Play()
				putAway.Stopped:Wait()
				phone:Destroy()
				wait(1.5)
				flashlight = false
				wait(2)
				cooldown = false
			end
		end
	end
end)
1 Like

I’m not sure, but don’t you have to set the priority of your looped animation over the default Idle animation, or turn off the Idle animation so it doesn’t take over?