Can anyone help me with Slower speed with tool equipped?

hello i have a crawl script and i want to make it where if someone has a tool equipped there crawl will be a little slower and a different animation will play but i can not get it any help? i made it where if someone equips a tool then a value in the script will go true

	if key.KeyCode == Enum.KeyCode.C then
		if not isRunning then -- Crawling
			Humanoid.WalkSpeed = 10
			isRunning = true
			humanoid1.CameraOffset = Vector3.new(0, -1, -1.8)
			Anim:Play()
			Anim:AdjustSpeed(0)
			print("Crawling")
		elseif isRunning then -- Walking
			Humanoid.WalkSpeed = 16
			Anim:Stop()
			isRunning = false
			print("Running")
			humanoid1.CameraOffset = Vector3.new(0, 0, -0.59)
			else
			if script.EquippedTool.Value == true then
				if not isRunning then
					print("CrawlWitTool")
					Humanoid.walkSpeed = 7
					Anim:Stop()
					ToolAnim:Play()
				end
			end
		end
	end
end)

Probably :sweat_smile:

if key.KeyCode == Enum.KeyCode.C then
		if script.EquippedTool.Value == true then
			if not isRunning then
				print("CrawlWitTool")
				Humanoid.walkSpeed = 7
				Anim:Stop()
				ToolAnim:Play()
			end
		else
			if not isRunning then -- Crawling
				Humanoid.WalkSpeed = 10
				isRunning = true
				humanoid1.CameraOffset = Vector3.new(0, -1, -1.8)
				Anim:Play()
				Anim:AdjustSpeed(0)
				print("Crawling")
			elseif isRunning then -- Walking
				Humanoid.WalkSpeed = 16
				Anim:Stop()
				isRunning = false
				print("Running")
				humanoid1.CameraOffset = Vector3.new(0, 0, -0.59)
			end
		end
	end
end)

Oh thanks let me try it rn I will tell u if it works

It kinda works, when I hold a tool and crawl and press c again to get up I stay stuck

And it only works if I hold a tool then crouch, anyway to make it also update if I pull out the tool while crouching

if key.KeyCode == Enum.KeyCode.C then
		if script.EquippedTool.Value == true then
			if not isRunning then
				isRunning = true
				print("CrawlWitTool")
				Humanoid.walkSpeed = 7
				Anim:Stop()
				ToolAnim:Play()
			else
				Humanoid.WalkSpeed = 16
				ToolAnim:Stop()
				isRunning = false
				print("Running")
				humanoid1.CameraOffset = Vector3.new(0, 0, -0.59)
			end
		else
			if not isRunning then -- Crawling
				Humanoid.WalkSpeed = 10
				isRunning = true
				humanoid1.CameraOffset = Vector3.new(0, -1, -1.8)
				Anim:Play()
				ToolAnim:Stop()
				Anim:AdjustSpeed(0)
				print("Crawling")
			elseif isRunning then -- Walking
				Humanoid.WalkSpeed = 16
				Anim:Stop()
                ToolAnim:Stop()
				isRunning = false
				print("Running")
				humanoid1.CameraOffset = Vector3.new(0, 0, -0.59)
			end
		end
	end
end)

Edit : update

It still doesn’t work and it’s pretty buggy, when u pull it out while crouching it doesn’t slow the player down, if u try to get up while holding a tool it doesn’t allow you to, it only allows u to stand up with no tool

Also if u stop holding the tool while crawling u don’t go back to speed 10 and the animation of the tool being held is still playing

I update the code by inserting TooAnim:Stop()

make sure set the EquippedTool.Value = false when tool is unequipped
try this code Tool.Unequipped:Connect(function() script.EquippedTool.Value = false end)

Snipping since post is irrelevant.

i added some short cuts with functions

function CrawlingTool() 
	script.Parent.HumanoidRootPart.CanCollide = false
	Humanoid.HipHeight = -1.9
	humanoid1.CameraOffset = Vector3.new(0, -1, -1.8)
	Humanoid.WalkSpeed = 7
	Anim:Stop()
	ToolAnim:Play()
end

function Crawling() 
	script.Parent.HumanoidRootPart.CanCollide = false
	Humanoid.HipHeight = -1.9
	humanoid1.CameraOffset = Vector3.new(0, -1, -1.8)
	Humanoid.WalkSpeed = 10
	Anim:Play()
	ToolAnim:Stop()
	Anim:AdjustSpeed(0)
end

function StandingUp() 
	script.Parent.HumanoidRootPart.CanCollide = true
	Humanoid.HipHeight = 0
	humanoid1.CameraOffset = Vector3.new(0,0,-0.59)
	Humanoid.WalkSpeed = 16
	Anim:Stop()
	ToolAnim:Stop()
end
-- Short cut functions End -- 

UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
	if script.EquippedTool.Value == true then
		if not isRunning then -- This is crrawling but with a tool equipped
			isRunning = true
			print("CrawlWitTool")
			CrawlingTool()
		else
			isRunning = false
				print("Running")
				StandingUp()
			end
			
		else --- If No Tool is equipped/This is regular Crawling
		if not isRunning then -- Crawling
				isRunning = true
				Crawling()
			print("Crawling")
		elseif isRunning then -- Walking
				isRunning = false
				StandingUp()
			print("Running")
		end
	end
end
end)

Snipping since post is irrelevant.

“Advanced Flashlight” btw am I gonna have to put everytime tools name into this script? Cuz my games gonna have alot of tools so that is kinda gonna be annoying

Snipping since post is irrelevant.

So I have to define it everytime?

Or could I make it where in the script of the flashlight I make it where it makes a value inside the script the name of the tool so I wouldn’t have to define each tool?

Actually idk if that would work

Snipping since post is irrelevant.

I mean there’s more than 1 tool so wouldn’t this only work for one tool

Snipping since post is irrelevant.