How to make is so that a sword stays unequipped when player is running

I want to keep the player from equipping the sword when running

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local tool = Player.Backpack.Sword or Player.Character:FindFirstChild("Sword")
local connection
local equip = humanoid:LoadAnimation(game:GetService("ReplicatedStorage").Idle)
local Anim =  game:GetService("ReplicatedStorage").Animation
local RunAllowed = true

Player.Character.ChildAdded:Connect(function(child)
	if child:IsA("Tool") and  child.Name== "Sword"  then
		RunAllowed = false		
	end
end)
Player.Character.ChildRemoved:Connect(function(child)
	if child:IsA("Tool") and  child.Name== "Sword"  then
		RunAllowed = true
	end
end)

PlayAnim = Character.Humanoid:LoadAnimation(Anim)
UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift  and RunAllowed then
		Character.Humanoid.WalkSpeed = 35
	
		
		PlayAnim:Play()
		
		humanoid.Jumping:Connect(function(isActive)
			if isActive then
				PlayAnim:Stop()
				wait(0.5)
				PlayAnim:Play()
			end
		end)
		
	end
end)


UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16
		if PlayAnim.IsPlaying then
			PlayAnim:Stop()
		else 
			return
		end
	end
end)
```lua

you could disable the player’s toolbar while running, thats how other games handle it, works pretty well

I believe this is what you’re looking for:

--start running
UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift  and RunAllowed then
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		humanoid:UnequipTools()
		Character.Humanoid.WalkSpeed = 35


		PlayAnim:Play()

		humanoid.Jumping:Connect(function(isActive)
			if isActive then
				PlayAnim:Stop()
				wait(0.5)
				PlayAnim:Play()
			end
		end)
	end
end)

-- stop running
UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		Character.Humanoid.WalkSpeed = 16
		if PlayAnim.IsPlaying then
			PlayAnim:Stop()
		else 
			return
		end
	end
end)
local UserInput = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Backpack = Player:WaitForChild("Backpack")
local Sword = Backpack:WaitForChild("Sword")

local Replicated = game:GetService("ReplicatedStorage")
local Animation = Replicated:WaitForChild("Animation")
local Track = Animator:LoadAnimation(Animation)

local EquipConnection
local JumpConnection

UserInput.InputBegan:Connect(function(inputObject, wasProcessed)
	if wasProcessed then return end
	
	if inputObject.KeyCode == Enum.KeyCode.LeftShift then
		Humanoid.WalkSpeed = 35
		if not Track.IsPlaying then
			Track:Play()
		end
		
		if not JumpConnection then
			JumpConnection = Humanoid.Jumping:Connect(function(IsJumping)
				if IsJumping then
					Track:Stop()
				else
					Track:Play()
				end
			end)
		end
		
		if not EquipConnection then
			EquipConnection = Sword.Equipped:Connect(function()
				Humanoid:UnequipTools()
			end)
		end
	end
end)

UserInput.InputEnded:Connect(function(inputObject, wasProcessed)
	if wasProcessed then return end
	
	if inputObject.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16
		if Track.IsPlaying then
			Track:Stop()
		end
		
		if JumpConnection then
			if JumpConnection.Connected then
				JumpConnection:Disconnect()
			end
		end
		
		if EquipConnection then
			if EquipConnection.Connected then
				EquipConnection:Disconnect()
			end
		end
	end
end)