Can Anyone help me with my crawl script?

hello i have a crawl script and im trying to make it where if u equip a tool you move slower and have a custom animation, it works but doesnt at the same time, it sometimes doesnt change speeds/Animations after equipping a tool or unequipping a tool any help?

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()
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 -- 

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		if not isCrawling then -- if there crawling
			isCrawling = true
			CrawlWTool = false
			Crawling()
		else 
			isCrawling = false
			CrawlWTool = false
				StandingUp()
		end
		
		for i, v in pairs(Backpack:GetChildren()) do
			if v:IsA("Tool") then
				CrawlWTool = true
				v.Equipped:Connect(function(Equip) 
					if isCrawling and CrawlWTool then -- if they both are true
						isCrawling = true
						CrawlWTool = true
						CrawlingTool()
					elseif isCrawling and not CrawlWTool then  -- if there crawling but with no tool
						isCrawling = true
						CrawlWTool = false
						Crawling()
					elseif not isCrawling and not CrawlWTool then -- not crawling and not holding tool while crawling
						isCrawling = false
						CrawlWTool = false
						StandingUp()
					end
				end)
			end
		end
	end
end)
1 Like
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Character = script.Parent
local HMR = script.Parent:WaitForChild("HumanoidRootPart")
local Player = Players:GetPlayerFromCharacter(Character)
local Backpack = Player:WaitForChild("Backpack")
local Tool = Backpack:WaitForChild("Advanced Flashlight")
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Anim = Animator:LoadAnimation(script:WaitForChild("Animation"))
local ToolAnim = Animator:LoadAnimation(script:WaitForChild("CrawlAnimationTool"))
local isRunning = false
local isEquipped = false

Tool.Equipped:Connect(function()
	isEquipped = true
end)

Tool.Unequipped:Connect(function()
	isEquipped = false
end)

Humanoid.Running:Connect(function(Speed)
	if isEquipped then
		if Speed > 0 then
			ToolAnim:AdjustSpeed(1)
		else
			ToolAnim:AdjustSpeed(0)
		end
	elseif not isEquipped then
		if Speed > 0 then
			Anim:AdjustSpeed(1)
		else
			Anim:AdjustSpeed(0)
		end
	end
end)

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

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

function StandingUp() 
	HMR.CanCollide = true
	Humanoid.HipHeight = 0
	Humanoid.CameraOffset = Vector3.new(0,0,-0.59)
	Humanoid.WalkSpeed = 16
	Anim:Stop()
	ToolAnim:Stop()
end

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		if not isRunning then
			if isEquipped then
				isRunning = true
				print("CrawlingTool")
				CrawlingTool()
			elseif not isEquipped then
				isRunning = true
				print("Crawling")
				Crawling()
			end
		elseif isRunning then
			if isEquipped then
				isRunning = false
				print("RunningTool")
				StandingUp()
			elseif not isEquipped then
				isRunning = false
				print("Running")
				StandingUp()
			end
		end
	end
end)